【发布时间】:2023-03-15 03:49:01
【问题描述】:
我有一个Sheet1 中的单词列表,我需要从Sheets("Sheet2").Range("A1:A7500") 到Range 的末尾一一匹配。每当单词匹配时,我需要在Sheet1 中对其进行处理。该词在Sheets("Sheet2").Range("A1:A7500") 中出现多次。
以下代码仅查找单词一次。我不明白哪里出了问题。
Sub XMAX()
Dim lrow As Long
Dim cel As Range
Dim oRng As Range: Set oRng = Sheets("Sheet2").Range("A1:A7500")
Dim oFoundRng As Range, oLastRng As Range
lrow = Sheets("sheet1").Cells(Sheets("Sheet1").Rows.Count, "f").End(xlUp).Row
'''''''''''''''Sheet1'''''''''''''''
For Each cel In Range("f4:f" & lrow)
If IsEmpty(cel.Value) = False Then
Set oFoundRng = oRng.find(cel.Value)
Do While Not oFoundRng Is Nothing
If UCase(oFoundRng.Offset(0, 1).Value) = "ISAAC" Then
Range("X" & cel.Row).Value = "X"
ElseIf UCase(oFoundRng.Offset(0, 1).Value) = "YO" Then
Range("V" & cel.Row).Value = "X"
ElseIf UCase(oFoundRng.Offset(0, 1).Value) = "JAN" Then
Range("U" & cel.Row).Value = "X"
Else
MsgBox oFoundRng.Value
End If
Set oLastRng = oFoundRng
Set oFoundRng = oRng.FindNext(cel.Value) 'Getting Error(1004) here "unable to get findnext property of the range class"
If oLastRng >= oFoundRng Then
Exit Do
End If
Loop
Else
End If
Next
【问题讨论】:
-
If oLastRng >= oFoundRng Then的目的是什么? -
@DisplayName 到
exit do如果所有 'Cel.Value' 都已找到。我认为If oLastRng >= oFoundRng Then Exit Do声明是错误的,因为它早早退出了do loop