您好我有一个工作表,其中日期存储在列中,我想写一个宏来切割数据并将数据粘贴到B行。请参阅附图。
我已经编写了这段代码:
Sub test()
Dim rng, copy_paste_range As Range
Set rng = Range(Range("C2"), Range("C2").End(xlToRight))
For Each r In rng
Range(Range(r.Address), Range(r.Address).End(xlDown)).Copy
'last_row = ThisWorkbook.Worksheets("Sheet1").Cells(Row.Count, 1).End(xlUp).Row
LastLine = Range(("B" & Rows.Count).End(xlUp).Row + 2).Select
LastLine.Paste
Next r
End Sub
但是,当我从每列复制数据时,我总是希望将1行留空,但我总是收到错误:
LastLine = Range(("B" & Rows.Count).End(xlUp).Row + 2).Select
LastLine.Paste
答案 0 :(得分:1)
你已经将rng变暗作为一个变体,你也应该将r作为范围调暗
Sub Button1_Click()
Dim rng As Range, r As Range
Set rng = Range(Range("C2"), Range("C2").End(xlToRight))
For Each r In rng.Cells
Range(Range(r.Address), Range(r.Address).End(xlDown)).Copy Range("B" & Rows.Count).End(xlUp).Offset(2)
Next r
End Sub