+ Reply to Thread
Results 1 to 7 of 7

Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

  1. #1
    Registered User
    Join Date
    04-21-2011
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

    Here's an easy example of what I'm trying to do (the excel file I'm actually working with has 500+ different sheets). I'd like to have a macro that could give me this output on sheet1 of the file I attached.

    145 abc p
    121 def q
    136 hij r
    188 klm s
    100 hi hehe
    102 bye lol
    888 aaa zzz
    666 bbb yyy
    111 ccc xxx
    222 ddd www
    333 eee vvv

    So basically, the macro should take the first column from sheets 2, 3, and 4 and put them in a single column on sheet1, with no space between entries. Similarly for the 2nd and 3rd column.

    I'd really appreciate any help any of you could provide. Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

    Try this:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-21-2011
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

    Thanks, that worked! One question, though. I actually don't want to do this for every worksheet in my workbook. I have 532 consecutive sheets where I want this done. I tried to modify your code to use a for loop, but I get a bug with:
    If ws.Name <> "CusipData" Then


    Dim i As Integer
    Dim j As Integer
    i = 1
    j = ActiveSheet.Index + 1
    For i = 1 To 532
    If ws.Name <> "CusipData" Then
    ws.UsedRange.Columns(1).Copy Sheets("CusipData").Range("L" & Rows.Count).End(xlUp)(2)
    ws.UsedRange.Columns(3).Copy Sheets("CusipData").Range("M" & Rows.Count).End(xlUp)(2)
    ws.UsedRange.Columns(20).Copy Sheets("CusipData").Range("N" & Rows.Count).End(xlUp)(2)
    End If
    j = j + 1
    Next i

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

    Please add code tags. Perhaps this, if you know the sheets you want run from the 2nd to 533rd?
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-21-2011
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

    When I run that code, I get this compile error: Invalid Next control variable reference

    I tried switching Next ws to Next i, and I got this runtime error: The information cannot be pasted because the Copy area and the paste area are not the same size and shape.

    I thought the second error might've been caused by a few sheets where one of the columns is longer than the other two (not sure if there are actually any sheets like this), so I commented out the 2nd and 3rd lines of the for loop. I got the same error, though.

    Any ideas? Thanks again.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

    Yes, thanks, I missed the Next error. See if this works:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-15-2012
    Location
    Africa
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet

    awesome help! thanks

+ 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