我从列表框中获取ID,然后扫描Excel工作表(ID)以查明该ID是否存在。如果不是,我必须最后添加它。如果是,我必须找出ID存在的行。
我正在以这种方式循环
count = 1
count1=1
While (Worksheets("ID").Cells(Count, 1) <> "")
If StrComp(Worksheets("ID").Cells(Count, 2), list1.Value, vbTextCompare = 1) Then
count1=count
count = count +1
答案 0 :(得分:3)
您可以尝试使用FInd查看B列,以查看整个字符串上的单个不区分大小写的匹配,即
更新:如果您直接从活动X控件运行查找,则:
Private Sub List1_Click()
Dim rng1 As Range
Set rng1 = Sheets("ID").Columns("B").Find(List1.Value, , xlValues, xlWhole, , False)
If Not rng1 Is Nothing Then
MsgBox List1.Value & " found at " & rng1.Row
Else
MsgBox List1.Value & " not found"
End If
End Sub