VBA copy header in Sheet1 and paste in subsequent sheets

dellzy

Board Regular
Joined
Apr 24, 2013
Messages
146
Dear Excel Experts,

I've been trying the whole day and kinda give up on this. Am trying to do this automatically. Copy header from first worksheet to all other worksheets. But come to no avail. Below are my series of coding I've tried:-

Code:
Do While i <= Worksheets.Count
Sheets(i).Rows(1).EntireRow.Copy
Sheets(i + 1).Range("A1").Paste
i = i + 1
Sheets(i).Rows(1).Paste
Loop

Code:
For i = 1 To Worksheets.Count
Sheets(1).Rows(1).EntireRow.Copy
Sheets(i+1).Range("A1").Select
Selection.Paste
Next

Code:
For Each Worksheet In ActiveWorkbook.Worksheets
Sheets(1).Rows("1:1").Copy
Sheets(i).Rows("1:1").Paste
i=i+1
Next

I just don't know what is actually wrong with it. :( Please help. Really need this for 147 worksheets. :(
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this:
Copies Header from Sheet(1) to all other sheets
Code:
Sub Copy_Header()
Application.ScreenUpdating = False
Dim i As Long

    For i = 2 To Sheets.Count
        Sheets(1).Rows(1).Copy Destination:=Sheets(i).Rows(1)
    Next
Sheets(1).Cells(1, 1).Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
@My Aswer Is This, you shouldn't need the "Application.CutCopyMode = False" line if using Destination.
Try it, you shouldn't get the flashing dashes to say it is copying around Sheets(1).Rows(1).
 
Upvote 0
Oh, thank u thank u thank u! The code works perfect! You're my saviour! Yess! Yeayy!

Try this:
Copies Header from Sheet(1) to all other sheets
Code:
Sub Copy_Header()
Application.ScreenUpdating = False
Dim i As Long

    For i = 2 To Sheets.Count
        Sheets(1).Rows(1).Copy Destination:=Sheets(i).Rows(1)
    Next
Sheets(1).Cells(1, 1).Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks Mark.
@My Aswer Is This, you shouldn't need the "Application.CutCopyMode = False" line if using Destination.
Try it, you shouldn't get the flashing dashes to say it is copying around Sheets(1).Rows(1).
 
Upvote 0
Hello People,

FWIW, a simple one liner could do the job also.


Code:
Sub Test()
    Worksheets.FillAcrossSheets Sheet1.[A1:M1]
End Sub

Just change the range to suit.

Cheerio,
vcoolio.
 
Upvote 0
Correction: previous statement was in error. Apologies.
@ vcoolio, thanks for the tip.
 
Last edited:
Upvote 0
I have never seen this code before. Where do you find all these secrets?
Hello People,

FWIW, a simple one liner could do the job also.


Code:
Sub Test()
    Worksheets.FillAcrossSheets Sheet1.[A1:M1]
End Sub

Just change the range to suit.

Cheerio,
vcoolio.
 
Upvote 0
@My Aswer Is This it is not really a secret, you can record yourself doing it manually :)

Select the sheet tabs you want
Select the range you want copied on the sheet you are copying from
On the Home tab, in the Editing group click the Fill dropdown arrow.
Click Across Worksheets.
Click whatever option you want.

You'll get something like...
Code:
    Range("A1:F1").Select
    Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")).Select
    ActiveWindow.SelectedSheets.FillAcrossSheets Range:=Selection, Type:=xlAll

which the code vcoolio posted is a tidied up equivalent of i.e. the above would be

Code:
Sub Macro2()
    Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")).FillAcrossSheets Range:=Range("A1:F1"), Type:=xlAll
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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