+ Reply to Thread
Results 1 to 3 of 3

Thread: Copy First Row into the First Row of all worksheets

  1. #1
    Registered User
    Join Date
    12-28-2009
    Location
    Atlanta, Ga
    MS-Off Ver
    Excel 2007
    Posts
    16

    Copy First Row into the First Row of all worksheets

    Hello,

    I've been working on creating this line of script but keep getting errors. I need the first row on the first worksheet to copy to the remaining worksheets on the first row. Literally row 1 from the first sheet will pasted in row 1 of the remaining sheets. Here's the final script that I tried.

    Sub Top_Row_Paste()
    
    Dim ws As Worksheet, i As Integer, r As Range
    
    Set r = Worksheets(1).Range("A1")
    Set ws = Worksheet(i)
    i = i + 1
    
    For Each ws In ActiveWorkbook.Worksheets
       r.EntireRow.Copy Destination:=Range("A1")
    
    Next ws
       
    End Sub
    The Set r statement is all ways being highlighted even if i call the worksheet by name.

    Thanks for the help.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Copy First Row into the First Row of all worksheets

    Hello keith156,

    You didn't qualify your destination range with the object variable ws.
    Sub Top_Row_Paste()
    
    Dim ws As Worksheet, i As Integer, r As Range
    
    Set r = Worksheets(1).Range("A1")
    Set ws = Worksheet(i)
    i = i + 1
    
    For Each ws In ActiveWorkbook.Worksheets
       r.EntireRow.Copy Destination:=ws.Range("A1")
    
    Next ws
       
    End Sub
    Addendum: Worksheets index starts at 1, not 0
    Last edited by Leith Ross; 12-30-2009 at 03:04 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-28-2009
    Location
    Atlanta, Ga
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Copy First Row into the First Row of all worksheets

    Leith,
    Thanks for the reply. I tried to add the ws to the statement and got another error "mismatch" and "Script out of Range" errors. However, I changed the script to the following and it worked.


    Sub Top_Row_Paste()
    
    Dim ws As Variant, i As Integer, r As Range
    
    Set r = Worksheets(1).Range("A1")
    Set ws = Worksheets(Worksheets.Count)
    i = i + 1
    
    For Each ws In ActiveWorkbook.Worksheets
       r.EntireRow.Copy Destination:=ws.Range("A1")
    
    Next ws
       
    End Sub
    Thank you for the response!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0