くの、めんどくさいんだよな整数をnullにExcel VBA?
質問
って検出するか否かの整数を設定、ない場合、スキップのコードのループを使用if文).ここでは私なのです。
Do While hws.Cells(r, 9).Value <> ""
On Error Resume Next
ar = Null
ar = aws.Range("A:A").Find(hws.Cells(r, 2).Value).Row
If Not IsNull(ar) Then
'work with ar'
End If
r = r + 1
Loop
しかし、で ar = Null
課題はある。では"無効な利用のnull"です。
解決
見を返しま範囲:
Dim rf As Range
With aws.Range("A:A")
Set rf = .Find(hws.Cells(r, 2).Value)
If Not rf Is Nothing Then
Debug.Print "Found : " & rf.Address
End If
End With
-- http://msdn.microsoft.com/en-us/library/aa195730(事務所11).aspx
他のヒント
整数として定義された変数は、VBAにはNULLにすることはできません。あなたが欲しいものを行うための別の方法を見つける必要があります。例えば、異なるデータ型を使用またはnull(例えば-1)を示すために、マジックナンバーを使用します。
あなたのコード例では、いずれかのARがロング値が割り当てられます(Range.Rowが長い)、または、それはエラーがスローされます。
ちょうどバリアントとのisEmptyを使用します:
Dim i
If IsEmpty(i) Then MsgBox "IsEmpty"
i = 10
If IsEmpty(i) Then
MsgBox "IsEmpty"
Else
MsgBox "not Empty"
End If
i = Empty
If IsEmpty(i) Then MsgBox "IsEmpty"
'a kind of Nullable behaviour you only can get with a variant
'do you have integer?
Dim j as Integer
j = 0
If j = 0 Then MsgBox "j is 0"
所属していません StackOverflow