+ Reply to Thread
Results 1 to 7 of 7

Copy multiple columns in multiple workbooks into a seperate worksheet (problem with code)

Hybrid View

Sc0tt1e Copy multiple columns in... 02-27-2014, 11:05 AM
Sc0tt1e Re: Copy multiple columns in... 02-27-2014, 11:33 AM
AlphaFrog Re: Copy multiple columns in... 02-27-2014, 11:52 AM
Sc0tt1e Re: Copy multiple columns in... 02-28-2014, 07:31 AM
Sc0tt1e Re: Copy multiple columns in... 02-28-2014, 08:45 AM
polooop Re: Copy multiple columns in... 02-28-2014, 09:03 AM
Sc0tt1e Re: Copy multiple columns in... 02-28-2014, 09:34 AM
  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Copy multiple columns in multiple workbooks into a seperate worksheet (problem with code)

    The following code won't let me copy from the first workbook. I get a run time 1004 error stating "That command cannot be used on multiple selections".

    I would rather not have to copy this by column for each of the 4 workbooks so any help getting this in just 4 copy/pastes would be greatly appreciated.

    Sub Stats()
    '
    ' Stats Macro
    ' Copies Raw Data from Teamspreadsheets to MI spreadsheet to calculate stats
    '
    
    Application.ScreenUpdating = False
    
    Workbooks.Open Filename:= _
            "R:\Derivatives - Project Rosetta\BAU-GoLive\Redress Team Folder - DO NOT MOVE\Tracker\New CET Redress Team Trackers\Redress Tracker Team 1.xlsx"
        Sheets("Redress Tracker").Select
        Range("A4:C2000,I4:I2000,J4:J2000,K4:K2000,R4:R2000,S4:S2000,AD4:AD2000,AU4:AU2000,AW4:AW2000,BE4:BE2000,BF4,BF2000").Select
        Selection.Copy
        Sheets("Raw Data").Range("Redress Tracker MI.xlsx").Activate
        Range("A3").Select
        ActiveSheet.Paste
        
    Application.ScreenUpdating = True
    
    MsgBox (Complete!)
    
    End Sub
    Last edited by Sc0tt1e; 02-27-2014 at 11:33 AM.

  2. #2
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: Copy multiple columns in multiple workbooks into a seperate worksheet (problem with co

    Bumpity bump

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Copy multiple columns in multiple workbooks into a seperate worksheet (problem with co

    Sub Stats()
        '
        ' Stats Macro
        ' Copies Raw Data from Teamspreadsheets to MI spreadsheet to calculate stats
        '
        Dim strFile As String, i As Integer, wb As Workbook
        
        strPath = "R:\Derivatives - Project Rosetta\BAU-GoLive\Redress Team Folder - DO NOT MOVE\Tracker\New CET Redress Team Trackers\"
        
        Application.ScreenUpdating = False
        
        For i = 1 To 4
        
            Set wb = Workbooks.Open(Filename:=strPath & "Redress Tracker Team " & i & ".xlsx")
            
            Sheets("Redress Tracker").Range("A4:C2000,I4:K2000,R4:S2000,AD4:AD2000,AU4:AU2000,AW4:AW2000,BE4:BF2000").Copy
            Workbooks("Redress Tracker MI.xlsx").Sheets("Raw Data").Range("A3").Offset((i - 1) * 1997).PasteSpecial xlPasteValues
            
            wb.Close SaveChanges:=False     'close Redress Tracker Team workbooks
            
        Next i
        
        Application.ScreenUpdating = True
        
        MsgBox "Complete!", , "Copy Complete"
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: Copy multiple columns in multiple workbooks into a seperate worksheet (problem with co

    Almost there, I'm getting an error regarding the next i

    I get a Next without For error??? Any ideas what that is?

    Sub RefreshPivot()
    
        Dim strFile As String, i As Integer, wb As Workbook
        
            strPath = "R:\Derivatives - Project Rosetta\BAU-GoLive\Redress Team Folder - DO NOT MOVE\Tracker\New CET Redress Team Trackers\"
      
                For i = 1 To 4
    '
    ' RefreshPivot Macro
    ' Refreshes all 4 team pivots (*2) and the Master MI pivots (*2)
    '
    ' Keyboard Shortcut: Ctrl+Shift+G
    
        Application.ScreenUpdating = False
    
            Set wb = Workbooks.Open(Filename:=strPath & "Redress Tracker Team " & i & ".xlsx")
        
            Sheets("Pivot").Select
            ActiveSheet.PivotTables("Team" & i).PivotCache.Refresh
            ActiveSheet.PivotTables("UOW" & i).PivotCache.Refresh
        
            wb.Close SaveChanges:=True  'close Redress Tracker Team workbooks
                
        Next i
    
        ' Updates Master MI Sheet
        ActiveSheet.PivotTables("MasterTeams").PivotCache.Refresh
        ActiveSheet.PivotTables("MasterUOW").PivotCache.Refresh
        ActiveSheet.PivotTables("Allocation").PivotCache.Refresh
        
            '
        ' Stats Macro
        ' Copies Raw Data from Teamspreadsheets to MI spreadsheet to calculate stats
        '
        
            Set wb = Workbooks.Open(Filename:=strPath & "Redress Tracker Team " & i & ".xlsx")
            
            Sheets("Pivot").Range("F4:F15,H4:J15").Copy
            Workbooks("Redress Tracker MI.xlsm").Sheets("Raw Data").Range("Z3").Offset((i - 1) * 16).PasteSpecial xlPasteValues
            
            wb.Close SaveChanges:=True     'close Redress Tracker Team workbooks
                 
        Next i
        
        Application.ScreenUpdating = True
        
        MsgBox "Job Done!"
        
    End Sub

  5. #5
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: Copy multiple columns in multiple workbooks into a seperate worksheet (problem with co

    Bump, help!

  6. #6
    Registered User
    Join Date
    02-18-2014
    Location
    France
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Copy multiple columns in multiple workbooks into a seperate worksheet (problem with co

    Hi,

    You have line 5 this : For i = 1 To 4
    In the middle of your code : Next i
    And in the end of your code too: Next i !!

    You have to put another for i= 1 to 4 in your code or delete one next i depending on what you want to do.

  7. #7
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: Copy multiple columns in multiple workbooks into a seperate worksheet (problem with co

    Ohhhh, I thought the original i = 1-4 would work for both.

    Cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy & Pasting Multiple Cells and Ranges From Each Worksheet To a Seperate Sheet
    By tuc28869 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2013, 02:57 PM
  2. [SOLVED] VBA code to copy cell range from all worksheets for multiple workbooks
    By Beany213 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-21-2013, 12:34 PM
  3. Copy worksheet to multiple workbooks in a folder
    By MysticGenius in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2012, 07:10 AM
  4. code help - consolidating multiple workbooks into one worksheet
    By Schretter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2010, 06:41 PM
  5. Copy specific columns from mult workbooks to seperate workbook
    By excelgrrl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-02-2009, 10:12 AM

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