我需要将一组数据从一个 excel 文件复制到另一个 excel 文件。
粘贴时,我还需要将它们粘贴到所需列的下一个空行中。
此过程是否有任何宏编码,请帮助我
如果我正确理解您的问题,您需要做的就是:
像这样的东西就足够了,尽管它又快又脏。此外,我已经使它比它需要的更“详细”(因此效率更低),以试图使过程更清晰。(您并不真的需要我声明的所有变量,但我已将它们放入其中以使逻辑更加透明。)
Sub PasteToFollowingRow()
Dim wks As Excel.Worksheet
Dim rng_Source As Excel.Range
Dim rng_NextRowDown As Excel.Range
Dim l_LastRow As Long, l_LastColumn As Long
Set wks = ThisWorkbook.Worksheets("generation_copy")
l_LastRow = wks.UsedRange.Rows.Count
l_LastColumn = wks.UsedRange.Columns.Count
'Assumes that you'll never copy just one cell...
If (l_LastRow = 1 And l_LastColumn = 1) Then
Set rng_NextRowDown = wks.Cells(1, 1)
Else
Set rng_NextRowDown = wks.Cells(l_LastRow + 1, 1)
End If
Set rng_Source = ThisWorkbook.Worksheets("generation").UsedRange
rng_Source.Copy rng_NextRowDown
ExitPoint:
On Error Resume Next
Set rng_NextRowDown = Nothing
Set rng_Source = Nothing
Set wks = Nothing
On Error Goto 0
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Resume ExitPoint
End Sub