簡體   English   中英

復制數據並將其粘貼到最后一行

[英]Copy and Paste of data to last row

我有下面的代碼,它與MyCopy10都可以很好地工作。 但是下一個代碼MyCopy100不會復制實際電子郵件表的最后一行中的數據。 我不確定問題是否存在。

這是我的代碼:

Sub MyCopy10()
Dim myCols As Variant
Dim lastRow As Long
Dim c As Long

Sheets("Eamil-10").Activate

'Set columns you want to loop through in an array
myCols = Array("A", "B", "C", "D")

 '   Loop through columns array
For c = LBound(myCols) To UBound(myCols)
  '   Find last row in column A with data
    lastRow = Sheets("Eamil-10").Cells(Rows.Count, myCols(c)).End(xlUp).Row
 '       Copy data from Model sheet to summary sheet
    Sheets("Eamil-10").Range(Cells(1, myCols(c)), Cells(lastRow, 
 myCols(c))).Copy
    Sheets("Actual Email").Cells(1, c + 1).PasteSpecial Paste:=xlValues, _
        Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
Next c
 '     Sheets("Summary").Activate
 End Sub

Code:
 Sub MyCopy100()
Dim myCols As Variant
Dim lastRow As Long
Dim c As Long

  Sheets("Email-100").Activate

    '   Set columns you want to loop through in an array
    myCols = Array("A", "B", "C", "D")

    '   Loop through columns array
     For c = LBound(myCols) To UBound(myCols)
   '   Find last row in column W with data
    lastRow = Sheets("Email-100").Cells(Rows.Count, myCols(c)).End(xlUp).Row
    '       Copy data from Model sheet to summary sheet
    Sheets("Email-100").Range(Cells(1, myCols(c)), Cells(lastRow, 
     myCols(c))).Copy
    Sheets("Actual Email").Cells(1, c + 1).PasteSpecial Paste:=xlValues, _
        Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
  Next c
'     Sheets("Summary").Activate
 End Sub

嘗試下面的代碼,所有RangeCells都符合Sheets("Email-100")

Option Explicit

Sub MyCopy100()

Dim myCols As Variant
Dim lastRow As Long
Dim c As Long

' Set columns you want to loop through in an array
myCols = Array("A", "B", "C", "D")

With Sheets("Email-100")
    ' Loop through columns array
    For c = LBound(myCols) To UBound(myCols)
        ' Find last row in column with data
        lastRow = .Cells(.Rows.Count, myCols(c)).End(xlUp).Row

        ' Copy data from Model sheet to summary sheet
        .Range(.Cells(1, myCols(c)), .Cells(lastRow, myCols(c))).Copy
        Sheets("Actual Email").Cells(1, c + 1).PasteSpecial Paste:=xlValues, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False

        Application.CutCopyMode = False
    Next c
End With

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM