+ Reply to Thread
Results 1 to 6 of 6

Copy data from single sheet to multiple sheets

Hybrid View

  1. #1
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello maacmaac,

    There are two ways to accomplish this. Use strings are you have in your code, or use the Range method. I show you both...
    Sub Allocate2()
    
    Dim FirstRow As Variant
    Dim LastRow As Variant
    Dim i As Integer
    
    FirstRow = 2
    LastRow = 5
    
    Sheets("RawData").Select
    
        For i = 2 To Sheets.Count
           'String method
            Rows(FirstRow & ":" & LastRow).Copy
    
           'Range Method
            'Range(Rows(FirstRow), Rows(LastRow)).Copy
    
            With Sheets(i)
                .Range("A2").Paste
            End With
            
            FirstRow = FirstRow + 4
            LastRow = LastRow + 4
        Next i
    
    End Sub
    Sincerely,
    Leith Ross

  2. #2
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176
    Leith,

    Thanks for the comments. I ran into one more issue which is the next part of the code. The code I want to use is as follows but doesn't work.
        For i = 2 To Sheets.Count
            Rows(FirstRow & ":" & LastRow).Copy
    
            With Sheets(i)
                .Range("A2").Paste
            End With
            
            FirstRow = FirstRow + 4
            LastRow = LastRow + 4
        Next i
    The code will work if the code is like this
        For i = 2 To Sheets.Count
            Rows(FirstRow & ":" & LastRow).Copy
    
            Sheets(i).Select
            Range("A2").Select
            ActiveSheet.Paste
            Sheets("RawData").Select
            
            FirstRow = FirstRow + 61
            LastRow = LastRow + 61
        Next i
    Thanks

    P.S. is the first example the more effiecient way write the code?

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello maacmaac,

    Sorry, I was in a hurry and mistyped that line. Change it to this...
         For i = 2 To Sheets.Count
            Rows(FirstRow & ":" & LastRow).Copy
               Sheets(i).Range("A2").PasteSpecial Paste:=xlPasteAll
            FirstRow = FirstRow + 4
            LastRow = LastRow + 4
        Next i
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1