Excel宏将数据行复制到底行

Excel宏将数据行复制到底行,excel,vba,macros,Excel,Vba,Macros,你好 我试图创建一个宏,将当前月份行的数据复制到底部。刷新当前月份行,并且日期将更改为新月份(9月16日),但在刷新之前,请将数据复制到匹配的月份。但我似乎无法让它发挥作用 谢谢您的帮助。您的代码不需要这么长,请尝试下面的方法,并让我知道它是如何为您工作的:): 在工作表上放置一个按钮,并在创建新的月份之前按下它:)更改lRow=.Range(“a”和.rows.Count).End(xlUp).Row到lRow=.Range(“C”和.rows.Count).End(xlUp).RowFin

你好

我试图创建一个宏,将当前月份行的数据复制到底部。刷新当前月份行,并且日期将更改为新月份(9月16日),但在刷新之前,请将数据复制到匹配的月份。但我似乎无法让它发挥作用


谢谢您的帮助。

您的代码不需要这么长,请尝试下面的方法,并让我知道它是如何为您工作的:):


在工作表上放置一个按钮,并在创建新的月份之前按下它:)

更改
lRow=.Range(“a”和.rows.Count).End(xlUp).Row
lRow=.Range(“C”和.rows.Count).End(xlUp).Row
FinalRow=.Cells(rows.Count,“C”).End(xlUp).Row
。在这里,当我执行代码时,它不会复制数据。现在我承认我对代码做了一些改变。但是,它仍然包含与您的建议更改的核心逻辑。
    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