我最近就这样写了 VBA 代码。在我使用“付款”一词的地方,您可以使用“工资”一词并包括您的通配符,如下所示:
a.Cells(b.Row, 16).Value LIKE "*Wages*"
Sub ShortTerm()
Dim a As Range, b As Range
Dim i As Long
Dim j As Long
Dim p As Long
Dim value1 As Variant
i = 4 'the start row for pasting
Set a = ThisWorkbook.Sheets("Payments").UsedRange
For Each b In a.Rows
'in the next line change 16 to reflect the column where WAGES is found
If a.Cells(b.Row, 16).Value = "Short Term" Then
For j = 1 to 16
value1 = a.Cells(b.Row, j).Value
ThisWorkbook.Sheets("DestinationSheet").Cells(i, j).Value = value1
Next
i = i + 1
End If
Next
End Sub
显然我只复制了 16 列,所以如果这就是你想要的,这应该可以。如果您需要更多,请使该循环更大。可能有一种方法可以复制整行,但我最初只想要特定的单元格,我希望重新组织它们,这就是我这样做的原因。
在这里查看我博客上的帖子:
http://automatic-office.com/?p=355