Problem with copy paste

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
691
Office Version
  1. 365
Hi All

I need a little help with a snippet of code please, I think it is almost right but not quite. see below. I want to copy the used range in sheet Template to all sheets after sheet 10 and maintain the formatting and formulae

Cheers

Paul

VBA Code:
Sub copy_template()

Dim wsVar As Worksheet

Dim i As Integer
For i = 11 To ThisWorkbook.Worksheets.Count
     ThisWorkbook.Worksheets("Template").UsedRange.Copy ThisWorkbook.Worksheets(i).Range("A1").Paste
Next i

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Maybe something like this :
VBA Code:
Sub copy_template()

    Dim i As Integer, oTopLeftCell As Range
    
    With ThisWorkbook.Worksheets("Template").UsedRange
        Set oTopLeftCell = .Cells(1, 1)
        .Copy
    End With
    
    For i = 11 To ThisWorkbook.Worksheets.Count
          ThisWorkbook.Worksheets(i).Range(oTopLeftCell.Address).PasteSpecial xlPasteAll
    Next i

End Sub
 
Upvote 0
Solution
Depending on whether you later discover columns width to be an issue, you may want to add the line in blue before that PasteSpecial Line.
PS: It needs to be done first otherwise it can mess with alignment of cells using wrap text.

Rich (BB code):
    ThisWorkbook.Worksheets(i).Range(oTopLeftCell.Address).PasteSpecial xlPasteColumnWidths
    ThisWorkbook.Worksheets(i).Range(oTopLeftCell.Address).PasteSpecial xlPasteAll
 
Upvote 0
thanks so much, that worked like a dream :)

The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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