-4
我的代碼如下:我試圖向計添加到我的代碼中發現搜索次數
Dim ws As Worksheet
Dim ExitLoop As Boolean
Dim SearchString As String, FoundAt As String
Set ws = Worksheets("detail_report")
On Error GoTo Err
Set oRange = ws.Cells
SearchString = "front input"
Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _
LookAt:=xlPart, 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
Err:
MsgBox Err.Description
End Sub
我加入了下面的代碼,但不知道如何添加計數器部分:
Dim S As String
Dim count As Integer
這不是很清楚 - 你能解釋一下你想要的東西的櫃檯,你希望它是如何工作的? –
計算如何在Excel工作表中找到搜索字符串中的單詞@ Grade'Eh'Bacon – Dayday
我認爲如果您解釋(用語言,而不是VBA代碼)您嘗試使用您的程序完成的工作將會有所幫助。現在,我實在無法告訴它發生了什麼事,而且你已經制定了以「如果不適合」開頭的結構......這讓我感到困惑。就目前來看,我不認爲這會在結束之前進行超過1場比賽[雖然我可能會誤解快速閱讀],所以看起來它並沒有達到你期望的水平。 –