美好的一天,
我正在尝试创建一个将数据从当前月份行复制到底部的宏。当前月份行将刷新,日期将更改为新月(sep-16),但在刷新之前,请将数据复制到匹配的月份。但我似乎无法让它发挥作用。
With test_example.Sheets("test")
FinalRow = .Cells(rows.Count, 1).End(xlUp).Row
'Loop through each row
For x = 2 To FinalRow
'Decide if to copy based on column B
ThisValue = .Cells(1, 2).Value
If ThisValue = "Aug--16" Then
Sheets("sheet 1").Range("B2:G2").Copy
lRow = .Range("A" & .rows.Count).End(xlUp).Row
.Range("A" & lRow + 1, "Z" & lRow + 1).Select
ActiveSheet.Paste
End If
Next x
End With
// edited code because i only have one sheet in the workbook
Sub CopyData()
FinalRow = Cells(Rows.Count, "C").End(xlUp).Row
'Loop through each row
For x = 2 To FinalRow
'Decide if to copy based on column B
ThisValue = Cells(1, 2).Value
If ThisValue = "Aug--16" Then
Sheets("Sheet1").Range("B2:G2").Copy
lRow = Range("C" & Rows.Count).End(xlUp).Row
Range("A" & lRow + 1, "Z" & lRow + 1).Select
ActiveSheet.Paste
End If
Next x
End Sub
感谢您的帮助。
答案 0 :(得分:1)
您的代码不需要这么长时间,请尝试以下内容并让我知道它对您有用:):
sub copydata()
Dim lrow As Long
lrow = Sheets("test").Cells(Rows.Count, 3).End(xlUp).Row
With Sheets("test")
.Range("C2:G2").Copy
.Range("C" & lrow + 1).PasteSpecial xlPasteValues
End With
end sub
在工作表上放置一个按钮,然后在创建新月之前按下它:)