Copy past to last record in a row.

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,059
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have the code below and it all works well with MyCopy10. But the next code MyCopy100 is not copying the data in last row of sheet Actual Email. I am not sure as were problem is.


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 Email-10 sheet to Actual Email
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 A with data
lastRow = Sheets("Email-100").Cells(Rows.Count, myCols(c)).End(xlUp).Row
' Copy data from Email-100 sheet to Actual Email
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
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I always like to know what your wanting to do rather then be shown code that does not do what you want and hope we can figure out the problem.
 
Upvote 0
I am copying the data from sheets("Eamil-10") columns (A to D) till the last record in column A and then paste the same record in sheets("Actual Email") in last reocrd from column a. -- Step1
Then again copying the data from sheets("Email-100") columns (A to D) till the last record in column A and then paste the same record in sheets("Actual Email") in last reocrd from column a -- Step2
 
Upvote 0
Try this:
One piece of confusion is your sheet names.
One is named:
Eamil-10
Other is
Email-100

Why Email and then Eamil

You may need to modify sheet names unless this was done intentional.

Code:
Sub My_Script()
'Modified 4-16-18 4:15 AM EDT
Sheets("Eamil-10").Activate
Dim Lastrow As Long
Lastrow = Sheets("Eamil-10").Cells(Rows.Count, "A").End(xlUp).Row
Dim Lastrowa As Long
Lastrowa = Sheets("Email-100").Cells(Rows.Count, "A").End(xlUp).Row
Dim Lastrowb As Long
Lastrowb = Sheets("Actual Email").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Eamil-10").Range("A1:D" & Lastrow).Copy Sheets("Actual Email").Cells(Lastrowb, 1)
Lastrowb = Sheets("Actual Email").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Email-100").Range("A1:D" & Lastrow).Copy Sheets("Actual Email").Cells(Lastrowb, 1)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top