我正在尝试编写一个宏来过滤列E
和F
. 如果同时满足这两个条件,它会将整行复制到新工作表中。
这是我到目前为止所拥有的,但我无法让它工作......
Sub carving()
'482
SearchForString "482", "A01"
SearchForString "482", "A02"
SearchForString "482", "A03"
SearchForString "482", "A04"
'483
SearchForString "483", "A01"
SearchForString "483", "A02"
SearchForString "483", "A03"
SearchForString "483", "A04"
'484
SearchForString "484", "A01"
SearchForString "484", "A02"
SearchForString "484", "A03"
SearchForString "484", "A04"
'485
SearchForString "485", "A01"
SearchForString "485", "A02"
SearchForString "485", "A03"
SearchForString "485", "A04"
'482E
SearchForString "485", "A01"
SearchForString "485", "A02"
SearchForString "485", "A03"
SearchForString "485", "A04"
'482F
SearchForString "485", "A01"
SearchForString "485", "A02"
SearchForString "485", "A03"
SearchForString "485", "A04"
End Sub
Sub SearchForString(ColE, ColF)
'Dim LSearchRow As Long
Dim shtSearch As Worksheet
Dim shtCopyTo As Worksheet
Dim rw As Range
'LSearchRow = 2 'Start search in row 2
Set shtSearch = Sheets("example")
Set shtCopyTo = Sheets("test")
Dim LSearchRow As Integer
For LSearchRow = 2 To 30000
If Len(shtSearch.Cells(LSearchRow, 1).Value) > 0 Then
Set rw = shtSearch.Rows(LSearchRow)
If rw.Cells(7).Value = ColE And rw.Cells(6).Value = ColF Then
rw.Copy shtCopyTo.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
'Exit Do '? you say there's only one result to find
End If
End If
Next LSearchRow
End Sub
任何帮助,将不胜感激。