使用下面的函數來得到你的結果。您可以解析此功能的任何內容以在Sheet2中獲得結果。
Private Function filtercontent(content As String) As String
Lastrow = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Lastrow
If InStr(Cells(i, 2), content) > 0 Then
Worksheets("Sheet1").Range("A" & i, "C" & i).Copy
With Worksheets("Sheet2")
.Range("A" & .Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End If
Next i
End Function
或
Private Function filtercontent(content As String) As String
Dim Lastrow As Long
Dim i As Integer
Lastrow = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Lastrow
If InStr(Cells(i, 2), content) > 0 Then
Worksheets("Sheet1").Range("A" & i, "C" & i).Copy Worksheets("Sheet2").Range("A" & Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row + 1)
End If
Next i
End Function
例如,如果你想申請馬過濾然後
Sub testing()
filtercontent ("Horse")
End Sub