VBA: Copy all rows with data from one sheet and paste on bottom of another

Archived-1715

New Member
Joined
Sep 5, 2012
Messages
28
Hi,

In sheet4 I have data from column A:AC.
it can have sometimes 10 rows of data or sometimes only 1 row of data it is always random.

I need help writing VBA macro to copy only all the rows with data only and paste it below the last cell with data on sheet 5.

Thanks alot.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Give this a try
Code:
Sub cpynpst()
Dim sh4 As Worksheet, sh5 As Worksheet, lr As long, rng As Range
Set sh4 = Sheets("Sheet4")
Set sh5 = Sheets("Sheet5")
lr= sh4.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh4.Range("A2:A" & lr)
rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2)
End Sub
 
Last edited:
Upvote 0
Thanks it a lot works but there is one problem, it paste everything in correct place except it shifts everything to left one after 5th column? how can this be fixed please.
 
Upvote 0
Give this a try
Code:
Sub cpynpst()
Dim sh4 As Worksheet, sh5 As Worksheet, lr As long, rng As Range
Set sh4 = Sheets("Sheet4")
Set sh5 = Sheets("Sheet5")
lr= sh4.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh4.Range("A2:A" & lr)
rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2)
End Sub

Hi

thanks alot it worked like a charm, I had some error in my other sheet. Thanks again
 
Upvote 0
Thanks it a lot works but there is one problem, it paste everything in correct place except it shifts everything to left one after 5th column? how can this be fixed please.

There is nothing in the code provided above that would cause such a shift. Do you have event code in one of your sheets that might be activated by the change when items are pasted into it? If not, I have no clue what is happening.
 
Upvote 0
Hello JLGWhiz, the Code works like a charm, however there is bit of an issue, it copies all columns in from the source table. But i only want columns A to AQ. Your help is much appreciated.
 
Upvote 0

Forum statistics

Threads
1,216,088
Messages
6,128,744
Members
449,466
Latest member
Peter Juhnke

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