Domanda

Sto cercando di rilevare se un intero è stato fissato, e in caso contrario, saltare la maggior parte del codice in loop (utilizzando un'istruzione if). Ecco quello che ho così per.

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

Tuttavia, quando l'eseguo, ar = Null ha problemi. Si dice "utilizzo non valido di null".

È stato utile?

Soluzione

Trova restituisce un intervallo:

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(office.11).aspx

Altri suggerimenti

Le variabili definite come Integer non può essere NULL in VBA. Si dovrà trovare un altro modo per fare quello che vuoi. ad esempio utilizzare un diverso tipo di dati o utilizzare un numero magico per indicare nullo (es -1).

Nel codice esempio, sia ar verrà assegnato un valore Long (Range.Row è un Long) o genera un errore.

basta usare una variante e 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"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top