0
Excel - VBA 我想知道如何使用VBA查找Excel範圍的行。防爆。 「要找到的單詞」,這不僅僅是單元格的值,而是一個字符串的單詞。例如,查找字符串「網絡」到「需要幫助來映射網絡打印機」字符串的方法。查找單元格到單元格
Sub SearchForSfb()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 1
LSearchRow = 1
'Start copying data to row 2 in Open (row counter variable)
LCopyToRow = 2
While Len(Range("E" & CStr(LSearchRow)).Value) > 0
'If value in column E = "word to be found", copy entire row to Open
If Range("E" & CStr(LSearchRow)).Value = "word to be found" Then
'Select row in Data to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into SFB in next row
Sheets("SFB").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
Sheets("SFB").Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Data to continue searching
Sheets("Data").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
參見[短語內計數的關鍵字(http://stackoverflow.com/questions/32860792/count-keywords-within-phrases/32878493#32878493) – Jeeped