Link to home
Start Free TrialLog in
Avatar of Jagwarman
Jagwarman

asked on

Insert data on every worksheet based on current worksheet

I need to insert the same header row [Row 1 in sheet called Data] into every tab in my workbook. Can an expert provide me with VBA to do this

Thanks
Avatar of Naresh Patel
Naresh Patel
Flag of India image

For this not required macro.

Step 1 copy your Header (Data sheet)

Step 2 Right click on sheet tab - select All sheet.

Step 3 Press ctrl & click on Data Sheet so it will get unselected from group

Step 4 select any sheet and past your header.

Step 5 Done.

Thanks
Avatar of Pratima
try this macros

Sub CopyRowHeader()
     
    Application.CutCopyMode = True
     
    Dim Counter As Long, i As Long
     
    Counter = Sheets.Count
    For i = 1 To Counter
        Sheets("Sheet1").Cells(1, 1).EntireRow.Copy
        Sheets(i).Cells(1, 1).PasteSpecial
         
    Next i
     
    Application.CutCopyMode = False
End Sub


OR

Sub CopyHeader()
    Dim wsSheet As Worksheet
    For Each wsSheet In ThisWorkbook.Worksheets
        wsSheet.Rows(1).Value = Worksheets("Sheet1").Rows(1).Value
    Next wsSheet
End Sub


refer from
http://www.ozgrid.com/forum/showthread.php?t=77844
Avatar of Jagwarman
Jagwarman

ASKER

Pratima Pharande thanks for that but, they both insert the header in row 1 but they do not shift the data in the sheet down by one row therefor they overwrite the data on row one.

Can you assist
itjockey there could be 100 sheets so this is not something I want to do manually

Thanks
For this not required macro.

Step 1 copy your Header (Data sheet)

Step 2 Right click on sheet tab - select All sheet.

Step 3 Press ctrl & click on Data Sheet so it will get unselected from group

Step 4 select any sheet Add 1 row which shift down data to all sheet.

Step 5 Past your header  data in row 1.

Step 6 Done.

Thanks
This is one time process you don't have to do it for each & every sheet.

But I guess you prefer VBA...  :)

Thanks
itjockey thanks but yes as it is part of a much bigger Macro I prefer VBA
try something like this

 For i = 1 To Counter
Sheets(i).Range("A:A").FillDown
        Sheets("Sheet1").Cells(1, 1).EntireRow.Copy

        Sheets(i).Cells(1, 1).PasteSpecial
         
    Next i
Pratima Pharande

It's asking me for a variable. I'm not very good at this yet

Thanks
Pratima Pharande

I added
Dim Counter As Long, i As Long
and it ran but it did not copy the header row from my sheet called 'Data' to any of the other sheets. I did change sheet1 in the code to Data
ASKER CERTIFIED SOLUTION
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial