+ Reply to Thread
Results 1 to 7 of 7

Copy the same two columns from 5 sheets into one sheet?

Hybrid View

  1. #1
    Registered User
    Join Date
    10-29-2012
    Location
    Denver
    MS-Off Ver
    Excel 2007
    Posts
    3

    Copy the same two columns from 5 sheets into one sheet?

    Can anyone help with a macro to do the following?
    1. Copy data from Column A3 down to the last entry point (last entry will increase further down every week).
    2. Copy data from Column AM3 down to last entry point (last entry will increase further down every week).
    3. Copy column data 1 & 2 from more than one sheet, sheets "01" , "02" , "03" , "04" , "05" .
    THEN
    4. Put into a new sheet on same worksheet called "SUMMARY" A3 combined data in column A, and all AM3 combined data in column B.

    Thank you,

    Working on this as you read this but have yet to figure it out.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy the same two columns from 5 sheets into one sheet?

    Give this a try:

    Sub ConsolidateData()
    Dim ws As Worksheet, wsSUM As Worksheet, LR As Long
    
    Set wsSUM = ThisWorkbook.Sheets("SUMMARY")
    wsSUM.Range("A:B").Clear
    
    For Each ws In Sheets(Array("01", "02", "03", "04", "05"))
        With ws
            .Range("A3", .Range("A" & .Rows.Count).End(xlUp)).Copy wsSUM.Range("A" & Rows.Count).End(xlUp).Offset(1)
            .Range("AM3", .Range("AM" & .Rows.Count).End(xlUp)).Copy wsSUM.Range("B" & Rows.Count).End(xlUp).Offset(1)
        End With
    Next ws
    
    End Sub
    Last edited by JBeaucaire; 10-29-2012 at 09:43 AM. Reason: corrected 3rd line of code
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-29-2012
    Location
    Denver
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Copy the same two columns from 5 sheets into one sheet?

    Thank you, that worked good but only grabbed column A3 down from Sheet 01. It grabbed all columns AM3 perfectly, just it was missing the corresponding A column once we got to sheet 02. So I had a lot of "0"s at on the final Column A towards the bottom.

    Can you set it to grab the data but only paste values for column A3, maybe that was the issue? As the original Column A3 is a blend of data using other functions.

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Copy the same two columns from 5 sheets into one sheet?

    The below code is lengthy when comparing to JBeaucaire's code. But me too tried to get solution for your query and spent some time in writing the below code. So posting the code even though you got the shorter code.

    Option Explicit
    
    Sub ConsolidateData()
    Dim mSh As Worksheet, i As Byte, LRw As Long
    Dim arrSh() As Worksheet, shFound As Boolean
    Dim UsrSel As Byte, CursrLoc As Range
    
    ReDim arrSh(1 To 5)
    
    Set arrSh(1) = Sheets("01")
    Set arrSh(2) = Sheets("02")
    Set arrSh(3) = Sheets("03")
    Set arrSh(4) = Sheets("04")
    Set arrSh(5) = Sheets("05")
    
    For i = 1 To Sheets.Count
        If Sheets(i).Name = "Summary" Then
            shFound = True
            Exit For
        End If
    Next i
    
    If shFound Then
        UsrSel = MsgBox("Summary Sheet Already Exist." _
                 & "Do you want to replace it with New Sheet?" _
                 , vbQuestion + vbYesNo + vbDefaultButton2, "Sheet Exist")
        
        If UsrSel = 6 Then
            Application.DisplayAlerts = False
            Sheets("Summary").Delete
            Application.DisplayAlerts = True
        Else
            MsgBox "Unable to continue, since sheet already exist"
            Application.ScreenUpdating = True
            Exit Sub
        End If
    End If
    
    Application.ScreenUpdating = False
    
    Sheets.Add Before:=Sheets(1)
    
    ActiveSheet.Name = "Summary"
    Set mSh = ActiveSheet
    
    For i = 1 To UBound(arrSh())
        arrSh(i).Select
        Set CursrLoc = ActiveCell
        Range("A3:A" & Cells(Rows.Count, "A").End(xlUp).Row).Select
        Selection.Copy
        CursrLoc.Select
        
        mSh.Select
        LRw = Cells(Rows.Count, "A").End(xlUp).Row
        Cells(LRw + 1, "A").Select
        Selection.PasteSpecial xlPasteAll
        
        arrSh(i).Select
        Set CursrLoc = ActiveCell
        Range("AM3:AM" & Cells(Rows.Count, "AM").End(xlUp).Row).Select
        Selection.Copy
        CursrLoc.Select
    
        mSh.Select
        LRw = Cells(Rows.Count, "AM").End(xlUp).Row
        Cells(LRw + 1, "AM").Select
        Selection.PasteSpecial xlPasteAll
        Range("A3").Select
        
    Next i
    
    Application.CutCopyMode = False
    
    Application.ScreenUpdating = True
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy the same two columns from 5 sheets into one sheet?

    Who are you talking to? If me:

    Sub ConsolidateData()
    Dim ws As Worksheet, wsSUM As Worksheet, LR As Long
    
    Set wsSUM = ThisWorkbook.Sheets("SUMMARY")
    wsSUM.Range("A:B").Clear
    
    For Each ws In Sheets(Array("01", "02", "03", "04", "05"))
        With ws
            .Range("A3", .Range("A" & .Rows.Count).End(xlUp)).Copy 
            wsSUM.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
            .Range("AM3", .Range("AM" & .Rows.Count).End(xlUp)).Copy 
            wsSUM.Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
        End With
    Next ws
    
    End Sub

  6. #6
    Registered User
    Join Date
    10-29-2012
    Location
    Denver
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Copy the same two columns from 5 sheets into one sheet?

    JBeaucaire, thank you, that did it. Awesome.

    Now, I ran into a problem where this new data combined is too long for the database we work with. It needs to be broken up into sheets totaling no more than 3,500 rows. This generated 16,300 rows =) when combined. So Summary1, Summary2, Summar3, etc as needed worksheets is my next step. Thank you, this is a huge relief as is. In the meantime, I check with the website software and see if they can't change limits.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copy the same two columns from 5 sheets into one sheet?

    'ROWS TO SHEETS
    Here's a macro for taking a sheet and splitting into multiple sheets based on X-rows per sheet.


    The original question has been resolved, so this thread should really be closed. Please select Thread Tools from the menu above and mark the thread as solved. Thanks.
    Last edited by JBeaucaire; 12-27-2019 at 10:43 PM.

+ 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