Solved

Insert data on every worksheet based on current worksheet

Posted on 2014-02-20
11
272 Views
Last Modified: 2014-02-20
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
0
Comment
Question by:Jagwarman
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 8

Expert Comment

by:itjockey
ID: 39872771
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
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39872790
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
0
 

Author Comment

by:Jagwarman
ID: 39872803
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
0
 

Author Comment

by:Jagwarman
ID: 39872807
itjockey there could be 100 sheets so this is not something I want to do manually

Thanks
0
 
LVL 8

Expert Comment

by:itjockey
ID: 39872811
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
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 8

Expert Comment

by:itjockey
ID: 39872820
This is one time process you don't have to do it for each & every sheet.

But I guess you prefer VBA...  :)

Thanks
0
 

Author Comment

by:Jagwarman
ID: 39872826
itjockey thanks but yes as it is part of a much bigger Macro I prefer VBA
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39872835
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
0
 

Author Comment

by:Jagwarman
ID: 39872992
Pratima Pharande

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

Thanks
0
 

Author Comment

by:Jagwarman
ID: 39873049
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
0
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 500 total points
ID: 39873140
Try this..

Sub copyheader()
    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim ws1 As Worksheet

    Set ws1 = Sheets("Data")

    For Each ws In ActiveWorkbook.Worksheets

        If ws.Name <> "Data" Then
            ws.select
            ws1.Rows("1:1").Copy
            ws.Rows("1:1").Insert Shift:=xlDown
            Application.CutCopyMode = False
            ws.Range("a1").Select

        End If
    Next ws
ws1.select
    Application.ScreenUpdating = True

End Sub

Open in new window


Saurabh..
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now