Copy first row of Sheet1 to all worksheets in workbook with blank first row

rdoulaghsingh

Board Regular
Joined
Feb 14, 2021
Messages
105
Office Version
  1. 365
Platform
  1. Windows
Hello! I'm trying to write an Excel VBA script to copy the first row of "Sheet1" with current formatting and filter on and paste the values into the first row of every worksheet in the workbook if the worksheet is blank.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe:
VBA Code:
Sub CopyRow1If()
For Each sht In ActiveWorkbook.Worksheets
    If sht.Name <> "Sheet1" And Application.CountA(sht.Cells) = 0 Then
        With Sheets("Sheet1")
            .Rows(1).Copy
            sht.Rows(1).PasteSpecial xlValues
        End With
    End If
Next sht

End Sub
 
Upvote 0
Solution
Maybe:
VBA Code:
Sub CopyRow1If()
For Each sht In ActiveWorkbook.Worksheets
    If sht.Name <> "Sheet1" And Application.CountA(sht.Cells) = 0 Then
        With Sheets("Sheet1")
            .Rows(1).Copy
            sht.Rows(1).PasteSpecial xlValues
        End With
    End If
Next sht

End Sub
This is great! Thanks for the reply. Is there anyway to set the autofilter property on the first row of all sheets in this loop?
 
Upvote 0
This is great! Thanks for the reply. Is there anyway to set the autofilter property on the first row of all sheets in this loop?
You are welcome - thanks for the reply.
Is this what you want for autofilter?
VBA Code:
Sub CopyRow1If()
For Each sht In ActiveWorkbook.Worksheets
    If sht.Name <> "Sheet1" And Application.CountA(sht.Cells) = 0 Then
        With Sheets("Sheet1")
            .Rows(1).Copy
            sht.Rows(1).PasteSpecial xlValues
            Intersect(sht.UsedRange, sht.Rows(1)).AutoFilter
        End With
    End If
Next sht

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,743
Messages
6,132,456
Members
449,729
Latest member
davelevnt

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