我有一對可能有字符串的列,我想知道它們是哪一行。查找函數以查找多個字符串
Dim lx As Integer
Dim FoundExec As Range
With Worksheets("Load " & LoadNr(1)).Range("G10:G26")
Set FoundExec = .Find("Exec", LookIn:=xlValues)
If Not FoundExec Is Nothing Then
Dim FirstLoadAddress As String
FirstLoadAddress = FoundExec.Address
Do
lx = FoundExec.Row
Set FoundExec = .FindNext(FoundExec)
'Code...
Loop While FoundExec.Address <> FirstLoadAddress
End If
End With
這對我的作品,因爲它是應該的,但我想也找到值「OVS」,「OV」和「OS」,因爲相同的代碼是那些投入之後跟進。
我TREID
Dim lx As Integer
Dim FoundExec As Range
Dim FoundOVS As Range
Dim FoundOV As Range
Dim FoundOS As Range
Dim AllOSS As Range
With Worksheets("Load " & LoadNr(1)).Range("G10:G26")
Set FoundExec = .Find("Exec", LookIn:=xlValues)
Set FoundOVS = .Find("OVS", LookIn:=xlValues)
Set FoundOV = .Find("OV", LookIn:=xlValues)
Set FoundOS = .Find("OS", LookIn:=xlValues)
Set AllOSS = Application.Union(FoundExec, FoundOVS, FoundOV, FoundOS)
If Not AllOSS Is Nothing Then
Dim FirstLoadAddress As String
'Code...
FirstLoadAddress = AllOSS.Address
Do
lx = AllOSS .Row
Set AllOSS = .FindNext(AllOSS)
Loop While AllOSS.Address <> FirstLoadAddress
End If
End With
但是,輪流在不斷循環。
有沒有辦法快速做到這一點?爲什麼在正在進行的循環中轉換第二個?
這個問題似乎因爲你不能「聯合」多次搜索,然後在其上執行'.FindNext'。在'Do'後面用'Debug.Print AllOSS.Address'檢查你的代碼,然後你就會明白爲什麼'Do Loop'永遠不會退出。 –