0

Excel 32 ビットで正常に動作するこのプロジェクトがありますが、64 ビットでの実行に問題があります。

無効な数式 (Excel で評価できなかったもの) を処理するこの部分があります。32 ビットは、キャッチできるエラーをスローするために使用されましたが、64 ビットでは、よくわからない問題があるようです。コードがちょっと詰まった。

Sub Macro1()
    Dim x As Variant
    On Error Goto ErrH:
    ReDim x(1, 1)
    x(0, 0) = "=1+1"
    x(0, 1) = "=1+ "  ' <--this is a sample of what I refer to as Invalid formula
    x(1, 0) = "=1+2"
    x(1, 1) = "=1+1"


    Range("A1:B2").Value = x  ' <--Im stuck in this part. 
                              ' the program does not proceed beyond this point 
                              ' and does not throw error like it used to.

    'I do something here


    On Error Goto 0
   Exit Sub

ErrH:


    ' I have bunch of stuffs that I do here, basically, Error handling.


End Sub

コードで指定した行で Excel がエラーをスローするには、どうすればよいですか?

4

2 に答える 2

0

数式を検証するには、VBA で定義済みの関数を使用できます。

Right(text,number of character)
ISNUMBER(text)

整数としての薄暗い i:i=0 整数としての薄暗い j:j=0

for i = 0 to 1
    for j = 0 to 1
        if ISNUMBER(Right(x(i,j),1)) OR Right(x(i,j),1)=")" Then
        ' do anything you want if the formula is correct
        else
            Goto ErrH:
        End If
    next
next 

X は 2 次元配列であるため、このメソッドを使用して X の値を出力できるとは思いません。

Range("A1:B2").Value = x

それを出力する適切な方法は、ループに 2 を使用することです

dim i as integer :i=0
dim j as integer :j=0

for i = 0 to 1
    for j = 0 to 1
    Cells(i+1).value = x(i,j)
    next
next

メッセージを出力できるエラー処理

ErrH:
  MsgBox "Invalid Formula"
  exit sub
于 2013-05-03T04:30:07.563 に答える