我已经输入了autofilter代码来指定copypaste操作的标准,但不确定我是否正确完成了。
Sub test3()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim copyFrom As Range
Dim lRow As Long
Dim strSearch As String
Set ws1 = Worksheets("sheet1")
strSearch = "LOCAL"
With ws1
'~~> Remove any filters
.AutoFilterMode = False
lRow = .Range("L" & .Rows.Count).End(xlUp).Row
With .Range("L4:L" & lRow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
End With
'~~> Remove any filters
.AutoFilterMode = False
End With
'~~> Destination File
Set ws2 = Worksheets("Sheet2")
With ws2
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lRow = 1
End If
copyFrom.Copy .Rows(lRow)
End With
Worksheets("Sheet2").Columns().AutoFit
Cells(1, 1).Activate
End Sub
非常感谢有人能突出显示我使用的代码出了什么问题。 感谢。