【发布时间】:2021-06-28 14:30:23
【问题描述】:
我正在尝试将一系列数据从一个工作表复制到另一个工作表。范围由与设定值匹配的 A 列中的值定义。我已经能够将具有指定值的每个单元格添加到范围对象中,但是我现在必须选择范围对象中单元格行中的所有数据,以便将它们复制到另一张表中。有什么建议吗?
另外,我对 VBA 很陌生,所以我确信我的代码格式很糟糕,但我真的只需要解决这个特殊问题。感谢您的帮助!
Dim allAsNum As Range
Dim currAsNum As Range
Dim asnum
Dim j
Sheets("Full Log").Select
asnum = "searchingvalue"
For j = 2 To CInt(Cells(Rows.Count, "A").End(xlUp).Row)
If Range(Sheets("Full Log").Cells.Address).Cells(j, 1).Value = asnum Then
If allAsNum Is Nothing Then
Set allAsNum = Range(Sheets("Full Log").Cells.Address).Cells(j, 1)
Else
Set allAsNum = Union(allAsNum, Range(Sheets("Full Log").Cells.Address).Cells(j, 1))
End If
End If
Next j
Set currAsNum = allAsNum.Rows 'This is the line that I can't figure out
currAsNum.Select
【问题讨论】:
-
allAsNum.EntireRow.Copy YourTargetRange -
AdvancedFilter 是一种根据选择标准复制数据的更有效方法。