1
正如標題所說,這是可能的和如何?EXCEL VBA將搜索結果存儲在數組中?
我找到.Find
函數來搜索列的值,我想要的是,然後可以將所有地址保存在數組中?
的代碼看起來是這樣的:
Set wsRaw = Worksheets("raw_list")
Set oRange = wsRaw.Columns(PhaseCol)
SearchString = "control"
Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Set bCell = aCell
FoundAt = aCell.Address
Do While ExitLoop = False
Set aCell = oRange.FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
FoundAt = FoundAt & ", " & aCell.Address
Else
ExitLoop = True
End If
Loop
Else
MsgBox SearchString & " not Found"
End If
MsgBox "The Search String has been found these locations: " & FoundAt
Exit Sub
至於現在我有一個MsgBox
只是爲了顯示結果。如果可能的話,這個想法是將結果存儲在一個數組中。
非常感謝你的快速回復! – Andreas
這很容易,考慮到你從我的博客拿起代碼的事實:D –
哦,然後雙倍謝謝你:) – Andreas