Macro Copy Main page to all worksheets

dawnwong77

New Member
Joined
Jul 24, 2017
Messages
1
I created a spreadsheet where I extract information from the main tab to multiple tabs based on customer number. I need to now add a header from the main sheet to all other sheets and having a hard time with a macro that will do this.

I need to Copy cells A1-M5 from tab Aging and paste to all other worksheets not Aging
Any assistance is appreciated
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Welcome to board :)

Try the below code

Code:
Sub CopyHeader()

Dim ws As Worksheet

For Each ws In Worksheets
    If ws.Name <> "Aging" Then
        ws.Range("A1:M5").Value = Sheets("Aging").Range("A1:M5").Value
    End If
Next ws

End Sub
 
Upvote 0
I created a spreadsheet where I extract information from the main tab to multiple tabs based on customer number. I need to now add a header from the main sheet to all other sheets and having a hard time with a macro that will do this.

I need to Copy cells A1-M5 from tab Aging and paste to all other worksheets not Aging
Any assistance is appreciated
Where do you want the copied data to be pasted on the other sheets?
 
Upvote 0
Thanks this works but does not paste the picture included in the range or the formatting can this be added?
 
Upvote 0
Thanks this works but does not paste the picture included in the range or the formatting can this be added?

How about this ?

Code:
Sub CopyHeader()

Dim ws As Worksheet

For Each ws In Worksheets
    If ws.Name <> "Aging" Then
        Sheets("Aging").Range("A1:M5").Copy
        With ws
            .Range("A1").Select
            .Paste
        End With
    End If
Next ws

End Sub
 
Upvote 0
How about this ?

Code:
Sub CopyHeader()

Dim ws As Worksheet

For Each ws In Worksheets
    If ws.Name <> "Aging" Then
        Sheets("Aging").Range("A1:M5").Copy
        With ws
            .Range("A1").Select
            .Paste
        End With
    End If
Next ws

End Sub

I get a range error
 
Upvote 0
I get a range error

Yeah you need to activate the sheet in order to select a range within the sheet ... Try the below revised code

Code:
Sub CopyHeader()

Dim ws As Worksheet

For Each ws In Worksheets
    If ws.Name <> "Aging" Then
        Sheets("Aging").Range("A1:M5").Copy
        With ws
            .Activate
            .Range("A1").Select
            .Paste
        End With
    End If
Next ws

End Sub

This may not be the "best" way to do it but is working for me to copy the pictures as well
 
Last edited:
Upvote 0
Yeah you need to activate the sheet in order to select a range within the sheet ... Try the below revised code

Code:
Sub CopyHeader()

Dim ws As Worksheet

For Each ws In Worksheets
    If ws.Name <> "Aging" Then
        Sheets("Aging").Range("A1:M5").Copy
        With ws
            .Activate
            .Range("A1").Select
            .Paste
        End With
    End If
Next ws

End Sub

This may not be the "best" way to do it but is working for me to copy the pictures as well

Thanks that works any chance you can help with adding in some page formatting
I want to repeat rows 1:5 on each page and sent to Landscape fitted to one page wide no setting on tall

THanks alot
 
Upvote 0
You are welcome. Try the below code, this should take care of the other items you've requested

Code:
Sub CopyHeader()

Application.ScreenUpdating = False

Dim CurrWs As Worksheet, Cell As Range
    Set CurrWs = ActiveSheet
    Set Cell = ActiveCell

Dim ws As Worksheet, CNT As Single

For Each ws In Worksheets
    If ws.Name <> "Aging" Then
        CNT = CNT + 1
        Sheets("Aging").Range("A1:M5").Copy
        With ws
            .Activate
            .Range("A1").Select
            .Paste
            .PageSetup.FitToPagesWide = 1
            .PageSetup.FitToPagesTall = False
            .PageSetup.PrintTitleRows = "$1:$5"
            .PageSetup.Orientation = xlLandscape
            .Range("A1").Select
        End With
    End If
Next ws

CurrWs.Activate
Cell.Select

MsgBox "Task completed for all " & CNT & " sheets", vbInformation

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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