我正在创建一个宏,将标题下的所有数据复制到另一个工作表。
我有这样的代码:
Sub CopyData()
Dim a As Range
'Find "1" in Row 2
With Sheets(1).Rows(2)
Set a = .Find("1", lookat:=xlPart)
'If found, copy the column to range A1 of sheet2
If Not a Is Nothing Then
Columns(a.Column).EntireColumn.Copy _
Destination:=Sheets(2).Range("A1")
End If
End With
End Sub
我有一个问题:
Columns(a.Column).EntireColumn.Copy _
Destination:=Sheets(2).Range("A1")
EntireColumn.Copy
将包括复制标题。我只想复制标题下面的所有数据。
替换EntireColumn.Copy
?
答案 0 :(得分:0)
我会像下面这样说:
Sub CopyData()
Dim a As Range
With Sheets(1)
Set a = .Rows(2).Find("1", LookIn:=xlValues, lookat:=xlPart) '<--| try finding "1" in Row 2
'If found, copy the column to range A1 of sheet2
If Not a Is Nothing Then .Range(a.Offset(1), .Cells(.Rows.Count, a.Column).End(xlUp)).Copy Destination:=Sheets(2).Range("A1")
End With
End Sub