【发布时间】:2019-09-09 21:03:25
【问题描述】:
我正在尝试在工作簿中进行简单的复制行、粘贴行。我搜索了线程并尝试多次更改我的代码无济于事。
最接近工作的是这个,但它只复制一个匹配条件的实例。
我正在尝试创建一个循环,该循环将复制在其中一列中匹配的所有行。
因此,如果有 8 列,则第 7 列中具有匹配值的每一行都应复制到命名工作表。
Sub test()
Set MR = Sheets("Main").Range("H1:H1000")
Dim WOLastRow As Long, Iter As Long
For Each cell In MR
If cell.Value = "X" Then
cell.EntireRow.Copy
Sheets("X").Range("A" & Rows.Count).End(xlUp).PasteSpecial
End If
If cell.Value = "Y" Then
cell.EntireRow.Copy
Sheets("Y").Range("A" & Rows.Count).End(xlUp).PasteSpecial
End If
If cell.Value = "Z" Then
cell.EntireRow.Copy
Sheets("Z").Range("A" & Rows.Count).End(xlUp).PasteSpecial
End If
If cell.Value = "AB" Then
cell.EntireRow.Copy
Sheets("AB").Range("A" & Rows.Count).End(xlUp).PasteSpecial
End If
Application.CutCopyMode = False
Next
End Sub
我喜欢这样,因为我需要使用不同的条件来定位多个目标工作表,但我需要复制所有符合条件的行。
【问题讨论】: