[英]Copy and Paste of data to last row
I have the code below and it all works well with MyCopy10. 我有下面的代码,它与MyCopy10都可以很好地工作。 But the next code MyCopy100 is not copying the data in last row of sheet Actual Email.
但是下一个代码MyCopy100不会复制实际电子邮件表的最后一行中的数据。 I am not sure as were problem is.
我不确定问题是否存在。
here is my Code: 这是我的代码:
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
Try the code below, all Range
and Cells
are qualified with Sheets("Email-100")
. 尝试下面的代码,所有
Range
和Cells
都符合Sheets("Email-100")
。
Code 码
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.