如果我运行这段代码,为什么会出现需要对象的错误?:
Dim mitarbeiterStatus
Dim mitarbeiterCell As Variant
Set mitarbeiterCell = Nothing
Dim rowsinWorkflow As Integer
rowsinWorkflow = Worksheets("worksheet1").Range("A1").End(xlDown).Row
With Worksheets("worksheet1").Range("B2:B" & rowsinWorkflow)
Dim firstAddress
mitarbeiterCell = .Find(displayName, LookIn:=xlValues)
If Not mitarbeiterCell Is Nothing Then 'ERROR HERE
firstAddress = mitarbeiterCell.Address
Do
'.....
Set mitarbeiterCell = .FindNext(displayName)
Loop While Not c Is Nothing And mitarbeiterCell.Address <> firstAddress
顺便说一句,我试着这样做:https://msdn.microsoft.com/de-de/library/office/ff839746.aspx
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
答案 0 :(得分:1)
更改此行:
mitarbeiterCell = .Find(displayName, LookIn:=xlValues)
对此:
Set mitarbeiterCell = .Find(displayName, LookIn:=xlValues)