这部分FindNext会抛出错误1004,告诉我我的范围无法获取FindNext属性。起初它是在形式,但我读到这可能是问题所以我把它移动到一个模块,仍然它仍然在相同的部分抛出相同的错误。
Sub list_click(ByVal Form As UserForm)
Dim Count As Integer
Dim Index As Integer
Dim rRange As Range
Count = Form.ListBox1.ListCount
data = Sheets("IN").Range("AB6").Value
Sheets("DB").Select
Sheets("DB").Range("A2").Select
Set rRange = Columns(1)
For i = 0 To Count - 1
If Form.ListBox1.Selected(i) Then
Index = form.ListBox1.List(i)
End If
Next i
c = rRange.Find(What:=Index, LookIn:=xlValues, SearchDirection:=xlNext).Activate
If ActiveCell.Offset(0, 2) <> data Then
c = rRange.FindNext(After:=c)
End If
End Sub
答案 0 :(得分:0)
将变量net设置为a = set objB
Option Explicit 'First line in every module. Forces you to declare variables before use!
Sub list_click(ByVal Form As UserForm)
Dim Count As Integer
Dim Index As Integer
Dim rRange As Range, c As Range
Dim Data As Variant
Count = Form.ListBox1.ListCount
Data = Sheets("IN").Range("AB6").Value
Set rRange = Sheets("DB").Columns(1)
Dim i As Integer
For i = 0 To Count - 1
If Form.ListBox1.Selected(i) Then
Index = Form.ListBox1.List(i)
End If
Next i
Set c = rRange.Find(What:=Index, LookIn:=xlValues, SearchDirection:=xlNext)
If ActiveCell.Offset(0, 2) <> Data Then
Set c = rRange.FindNext(After:=c)
End If
End Sub