Ozgrid Excel Help & Best Practices Forums


XL Templates | XL Add-ins | XL Training | XL Estimating | XL Scheduling | XL Recovery | XL Trading | XL Financial | XL Conversion | XL Charting


+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Combine Dynamic Worksheets Into One Sheet

  1. #1
    Join Date
    25th October 2007
    Posts
    5

    Combine Dynamic Worksheets Into One Sheet


    Download Active Data For Excel > > DETAILS > >
    I have two sheets in this sample workbook attached and need to have the data from the Pending sheet and the Completed sheet to be combined into a third sheet in the same workbook. They have the same column headers and need a macro to combine them even as data is continuously added to both sheets as time goes on. I would greatly appreciate your help.
    Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.

  2. #2
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    51,285

    Re: Combine Worksheets Into One Sheet

    Create 2 Dynamic named ranges, then use;

    Code:
    Sub CombineEm()
    
    With Sheet3 'CodeName
        .UsedRange.Clear
        Range("DynaRange1").Copy .Range("A1")
        Range("DynaRange2").Copy .Cells(.Rows.Count, "A").End(xlUp)(2, 1)
    End With
        
    
    End Sub

  3. #3
    Join Date
    25th October 2007
    Posts
    5

    Re: Combine Dynamic Worksheets Into One Sheet

    Sorry I'm new to this. By naming 2 dynamic ranges do you mean insert and define the ranges for both the pending and completed sheets? I did that and then copied the code into sheet 3 but the macro did not work. Any suggestions? Thank you.

  4. #4
    Join Date
    1st December 2006
    Posts
    406

    Re: Combine Dynamic Worksheets Into One Sheet

    Hi there,

    Let me know if the following macro does the trick (you'll have to create a tab called "Combined" first though):

    Code:
    Sub CombineII()
    
    Dim lngLastRow As Long
    
    lngLastRow = Sheets("Combined").Range("A65536").End(xlUp).Row
    
        If lngLastRow > 1 Then
        Sheets("Combined").Range("A1:Q" & lngLastRow).ClearContents
        End If
    
    lngLastRow = Sheets("Pending").Range("A65536").End(xlUp).Row
    
    Sheets("Pending").Range("A1:Q" & lngLastRow).Copy Sheets("Combined").Range("A1")
    
    lngLastRow = Sheets("Completed").Range("A65536").End(xlUp).Row
    Sheets("Completed").Range("A2:Q" & lngLastRow).Copy
    Sheets("Combined").Select
    
    Range("A65536").End(xlUp).Offset(1, 0).Select
    
    ActiveSheet.Paste
    Application.CutCopyMode = False
    
    End Sub
    HTH

    Robert

  5. #5
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    51,285

    Re: Combine Dynamic Worksheets Into One Sheet

    It works fine and to create a dynamic named range, hover over dynamic. The code does NOT go into a Sheet, it goes into a standard module. That is, insert>Name>Define.

  6. #6
    Join Date
    25th October 2007
    Posts
    5

    Re: Combine Dynamic Worksheets Into One Sheet

    I've copied your code into the module attached in this sheet and for some reason nothing happens as I enable the macros...unless there is something else I'm doing wrong...
    Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.

  7. #7
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    51,285

    Re: Combine Dynamic Worksheets Into One Sheet

    DynaRange1 defined as;
    =OFFSET(Pending!$A$2,0,0,COUNTA(Pending!$A:$A)-1,COUNTA(Pending!$1:$1))

    DynaRange1 defined as;
    =OFFSET(Completed!$A$2,0,0,COUNTA(Completed!$A:$A)-1,COUNTA(Completed!$1:$1))

    Then run;
    Code:
    Sub CombineEm()
         
        With Sheet4 ' CodeName
            .UsedRange.Clear
            Range("DynaRange1").Copy .Cells(.Rows.Count, "A").End(xlUp)(2, 1)
            Range("DynaRange2").Copy .Cells(.Rows.Count, "A").End(xlUp)(2, 1)
        End With
         
         
    End Sub

  8. #8
    Join Date
    25th October 2007
    Posts
    5

    Re: Combine Dynamic Worksheets Into One Sheet

    Sorry I keep getting an error...is there any way that you could attach the spreadsheet that is working properly to the thread? Thank you for your help.

  9. #9
    Join Date
    1st December 2006
    Posts
    406

    Re: Combine Dynamic Worksheets Into One Sheet

    Hi there,

    To use my macro you'll either have to change all references to "Combined" to "Master" in the code or name the third tab as "Combined" instead of "Master".

    Have a look at the attached which is based on your original example.

    HTH

    Robert
    Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.

  10. #10
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    51,285

    Re: Combine Dynamic Worksheets Into One Sheet


    Create Excel dashboards quickly with Plug-N-Play reports.
    See working example.
    Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

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

     

Possible Answers

  1. combine worksheets
    By Dave Hawley in forum Excel RSS Feed Discussions
    Replies: 0
    Last Post: March 16th, 2009, 05:23
  2. Replies: 5
    Last Post: December 16th, 2008, 01:51
  3. Replies: 3
    Last Post: May 18th, 2007, 07:05
  4. Combine Worksheets from different workbook
    By serenapoh in forum EXCEL HELP
    Replies: 2
    Last Post: November 7th, 2005, 00:21
  5. Combine all worksheets into one??
    By magmafish in forum EXCEL HELP
    Replies: 1
    Last Post: August 7th, 2003, 06:14

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