我需要将一组excel文件中的一组数据复制到另一个excel文件中。
粘贴时,我还需要将它们粘贴到所需列中的下一个空行中。这个过程是否有任何宏编码请帮帮我
答案 0 :(得分:2)
如果我理解你的问题,你需要做的就是:
这样的东西应该足够了,尽管它很快而且很脏。此外,我使它更加“详细”(因此效率低下),而不是试图使过程更加清晰。 (你真的不需要我已声明的所有变量,但我已将它们放入以使逻辑更透明。)
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