+ Reply to Thread
Results 1 to 2 of 2

VBA to Loop & Paste same data to all worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    04-19-2011
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2003
    Posts
    7

    VBA to Loop & Paste same data to all worksheets

    Struggling with this. I'm trying to take columns A, B & C in "sheet1" and paste it into all the other sheets within the workbook. My first 2 loops work flawlessly, but the code in BOLD shown below bombs. I greatly appreciate any help on this - THANKS!
    Sub Z_Font()
    
    Dim iwsCount As Integer
    Dim I As Integer
    
    ' Set 'wsCount equal to the number of worksheets in the active workbook
    iwsCount = ActiveWorkbook.Worksheets.Count
    
    ' Begin the Loop
    For I = 1 To iwsCount
    Sheets(I).Select
    With Sheets(I).Cells
        With .Font
            .Name = "Arial"
            .Size = 8
        End With
    
        Range("A1").Select
            Columns("A:A").Select
        Selection.Insert Shift:=xlToRight
        Selection.Insert Shift:=xlToRight
        Selection.Insert Shift:=xlToRight
        
    ' trying this code for the heck of it
    
        Sheets("Sheet1").Select
        Columns("D:F").Select
        Selection.Copy
        Range("B1").Select
        ActiveSheet.Paste
    End With
         
    Next I
    
    End Sub
    Last edited by Leith Ross; 04-20-2011 at 01:18 PM. Reason: Added Code Tags and Bolded text since color doesn't work

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: VBA to Loop & Paste same data to all worksheets

    Hi mlgill

    maybe something like...
    Sub ptest()
        Myarray = Array("Sheet2", "Sheet3", "Sheet4")
        For Each xSheet In Myarray
            Worksheets("Sheet1").Columns("A:C").Copy
            With Sheets(xSheet).Columns(1)
                .Insert Shift:=xlToRight
            End With
        Next
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ 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