Copying Ranges

jose001

Board Regular
Joined
Mar 27, 2006
Messages
103
Morning everyone,

A few members helped me on Friday with a problem but I'm still struggling to get this piece of code to work. Can anyone spot what's wrong with this......

It's only copying the contents of one sheet but there are four there?

---------------------------------------------------------------------------------

Private Sub PrintHC_Click()
Dim i As Long
i = Worksheets("Printout").Cells(Rows.Count, 1).End(xlUp).Row + 1

Worksheets("Printout").Select

For Each sh In Worksheets
If sh.Name <> "Begin" And sh.Name <> "Index" And sh.Name <> "Codes" And sh.Name <> "Printout" Then
sh.Range("A2:M12").Copy Worksheets("Printout").Range("A" & i)
End If
Next sh



End Sub

--------------------------------------------------------------------------------

Thanks


Jose :)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi Jose

The code is copying each subsequent range over the previously pasted one. Try this to avoid:

Code:
Private Sub PrintHC_Click()
Dim i As Long
i = Worksheets("Printout").Cells(Rows.Count, 1).End(xlUp).Row + 1

Worksheets("Printout").Select

For Each sh In Worksheets
If sh.Name <> "Begin" And sh.Name <> "Index" And sh.Name <> "Codes" And sh.Name <> "Printout" Then
sh.Range("A2:M12").Copy Worksheets("Printout").Range("A" & i)
i = Worksheets("Printout").Cells(Rows.Count, 1).End(xlUp).Row + 1
End If
Next sh



End Sub
 
Upvote 0
Hey Richard, thanks very much for the quick reply. I have used your code but it's still not working? It's still copy the info from just one sheet. Does it matter that the sheets have the names...index (2), index (3) etc?
 
Upvote 0
It shouldn't do - it is going thru each sheet and checking that the name of the sheet isn't Begin, Codes, printout or Index then it is copying that sheet's given range. Unless you only have one sheet that isn't named one of the above, then it should copy each sequentially in turn.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,974
Members
448,537
Latest member
Et_Cetera

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