Excelmacros将数据行复制到最下面一行

美好的一天,

我正在尝试创build一个macros,将当前月份的数据复制到底部。 当前月份行被刷新,date将会更改为新月份(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 

谢谢你的帮助。

你的代码不需要那么长,请尝试下面的内容,让我知道它是如何工作:):

 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 

在工作表上放置一个button,并在创build新的月份之前按下它。