Я ищу текст / строки в листе Excel, предоставленном заказчиком.Проблема в том, что иногда функция поиска Excel работает, а иногда нет.Например, если лист Excel выглядит следующим образом:
PartID Description Reference
1234 abc R3
4567 def C34
4512 ghi R2
Допустим, я искал R2 и нашел его, но когда я ищу R3, он просто не попадет.После R2 он найдет что-нибудь похожее на R3, например, R33, R31 и т. Д. Похоже, что он начинает проверку с последней позиции, которая была позицией R2.Ниже моя функция:
Sub addFeedernoToFile(PARTS As Integer, ByRef counter As Integer, fileptrsq As String, ws_sq As Worksheet, tempList() As String)
Dim i As Integer, k As Integer, found As Integer
Dim LastAddress As String
Dim xlSearchWithin1 As XlSearchWithin
Set Search_Range = Columns("C")
For i = 1 To PARTS
searchstring = tempList(counter)
With Search_Range
Set c = ws_sq.Cells.Find(What:=searchstring, _
After:=ws_sq.Range("C3"), _
SearchOrder:=xlByColumns, _
MatchCase:=False, _
LookAt:=xlPart, _
SearchDirection:=xlNext)
On Error Resume Next
' keep track of where we are. If we are in the loop below and hit
' LastAddress this means we have looped back to the begining.
LastAddress = c.Address
'loop until we find the part
Do Until c Is Nothing
found = 1
Dim splitter() As String
splitter = Split(c.Value, ",")
For k = 0 To UBound(splitter)
If splitter(k) = searchstring Then
firstaddress = c.Address
itemRow = Mid(firstaddress, 4, Len(firstaddress) - 3)
feederno = ws_sq.Range("F" & itemRow)
counter = counter - 1
found = 0
Exit For
End If
Next
Set c = ws_sq.Cells.FindNext(After:=c)
'we loop until we find our part the file, and if found
'we break out then.
If found = 0 Then
Exit Do
End If
If LastAddress = c.Address Then
Exit Do
End If
Loop ' end do until
End With ' end with search_range
Next ' end for
End Sub
Спасибо.