如果单元格包含XYZ复制到新工作表,则为excel

时间:2013-11-01 10:12:03

标签: excel vba

我在SHEET1(ALL)上有一份下载的银行对帐单。 我有几个小部件沿着其中一个运行

=SUMIF(C:C,H3,D:D)

搜索H3中的值的描述(EG:* WAGES *)并总计D中的相应值。

我现在需要扩展它,以便将整个ROW复制到新的电子表格上。

如果可能的话,我也希望从输入框开始,这样我就可以一次搜索多个内容。

我见过/尝试过的各种代码只能用于行C中的确切值。但是银行对帐单的两次从不相同,如果可能的话,我希望它能够通过搜索。

感谢您的时间。

亲切的问候

Alex Nicol

1 个答案:

答案 0 :(得分:0)

我最近写过这样的VBA代码。在我使用单词付款的地方,您可以使用单词Wages并包含您的通配符,如下所示:

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