需要它search重复的logging,直到find标准

我对VBA还是一个新鲜的东西,正在努力处理下面的代码!

我正在尝试做的是让searchfunction通过列1中的所有单元格查找,并find单元格1的条件匹配PickerName2.Text和偏移单元格5 <> 0,然后偏移单元格6 =空白

我遇到的问题是有一个重复所有的方式下列1,只要它find匹配的名称PickerName2然后它检查偏移单元格5和6,因为这些不符合标准,它给了消息,他们aren'目前正在采摘。

这是即使进一步下来有logging匹配的标准。 我希望它查看所有logging,直到find标准,或者是否已经检查了列A中所有填充的单元格,并且没有任何匹配,则会提示它们当前没有select的消息。

我希望有人能帮助:-)

Private Sub CommandButton3_Click() Dim iRow As Long Dim ws As Worksheet Dim strSearch As String Dim aCell As Range Dim rng As Range, i As Long '~~> Set the sheet where you want to search the IMEI Set ws = Sheets("PickData") With ws '~~> Get the value which you want to search strSearch = PickerName2.Text '~~> Column A is Column 1 so Column B is 2. This is where we are searching '~~> xlWhole is used in the code below so that we find a complete match '~~> xlPart is supposed to be used when you are finding a partial match. Set aCell = .Columns(1).Find(What:=strSearch, LookIn:=xlValues, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) '~~> get the row of the cell where we found the match and add data to If Not aCell Is Nothing And aCell.Offset(0, 5).Value <> "" And aCell.Offset(0, 6).Value = "" Then MsgBox " " & PickerName2.Text & " is currently picking - " & aCell.Offset(0, 1) & " " & aCell.Offset(0, 2) _ & " " & aCell.Offset(0, 3) _ & " " UserForm1.Hide Else MsgBox " " & PickerName2.Text & " has no outstanding PIK!", vbExclamation PickerName2.Value = "" Exit Sub End If End With PickNo2.Value = "" PickerName2.Value = "" UserForm1.Hide End Sub 

我已经做了一些在线search,并尝试类似于下面的代码,但不断收到一个对象所需的错误,但不能看到我要去哪里错了?

 Dim rng As Range Dim i As Integer Dim finalrow As Integer finalrow = Sheets("PickData").Range("A10000").End(xlUp).Row For i = 2 To finalrow If Cells(i, 1).Value = UserForm1.PickerName2.Text And (Cell.Offset(i, 5) <> "") And (Cell.Offset(i, 6) = "") Then MsgBox " " & PickerName2.Text & " is currently picking - " & Cell.Offset(i, 1) & " " & Cell.Offset(i, 2) _ & " " & Cell.Offset(i, 3) _ & " " End If Next i 

你的第一个代码尝试使用Range.Find方法是一个好的开始。 现在通过使用Range.FindNext方法来扩展这个方法。

这个链接应该可以帮到你。

在你的第二个代码块中:

Cell.Offset …的引用可能应该是像Cells(i,1).Offset(0,5)和Cells(i,1).Offset(0,1)和Cells(i,1).Offset (0,3)。

另外,PickerName2的第二个引用应该用UserForm1进行限定,就像在UserForm1.PickerName2