【发布时间】:2017-05-28 09:23:23
【问题描述】:
我正在尝试根据匹配将单元格数据从一张表复制到另一张表。
我有一个 3 张工作簿。 “地点”、“可乐”和“HMS”。
在活动工作表“Place”上,如果 C14 列有“Coke”一词 - 我希望将 D14-H14 复制到工作表“Coke”。
类似地,如果 C15 包含“HMS” - 我只想将“D15-H15”复制到工作表“HMS”
我有一个宏可以复制整行,而我想要复制特定的单元格 - 它来自特定的 C:H。
Sub As_Of_Analysis_Sorting()
Dim lr As Long, lr2 As Long, r As Long
lr = Sheets("Place").Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Sheets("Coke").Cells(Rows.Count, "A").End(xlUp).Row
lr3 = Sheets("HMS").Cells(Rows.Count, "A").End(xlUp).Row
For r = lr To 2 Step -1
If Range("C" & r).Value = "Coke" Then
Rows(r).Copy Destination:=Sheets("Coke").Range("A" & lr2 + 1)
lr2 = Sheets("Coke").Cells(Rows.Count, "A").End(xlUp).Row
End If
If Range("C" & r).Value = "HMS" Then
Rows(r).Copy Destination:=Sheets("HMS").Range("A" & lr3 + 1)
lr3 = Sheets("HMS").Cells(Rows.Count, "A").End(xlUp).Row
End If
Range("A140").Select
Next r
End Sub
我如何做到这一点?
【问题讨论】: