+ Reply to Thread
Results 1 to 12 of 12

Consolidate rows from multiple worksheets in one based on cell criteria

  1. #1
    Registered User
    Join Date
    10-06-2011
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    5

    Consolidate rows from multiple worksheets in one based on cell criteria

    I am learning vba but I am running into a difficult challenge. I have been reading several threads but I am not reaching the desired output. Hope one of you can help

    I have a workbook with multiple worksheets. The layout of these worksheets are all the same.
    Every week I need to report all actions that have been completed. These actions originate from the different worksheets with the names

    PRIORITY 1, PRIORITY 2, PRIORITY 3, PRIORITY4

    If a cell in column G in any of the rows and in any of the worksheets previoisly mentioned has the value CLOSED or CANCELLED it should copy the entire row to the next available row in worksheet CLOSED.

    Some additional request are: Keep the first row of the sheet CLOSED the same but clear the rest of the sheet CLOSED at the each run of the macro to prevent double entries

    I have tried to combine several threads But I am too new at VBA to get it working. Hope sombody is up to the challenge

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Please Login or Register  to view this content.
    Last edited by snb; 10-10-2011 at 05:07 AM.



  4. #4
    Registered User
    Join Date
    10-06-2011
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Thanks for the tip and also thanks for the reply with the code. I have posted the dummy file to clarify. The posted vba gives an error on the

    " .autofilter 1,"Closed", xlor "Cancelled" "

    Could be because I'working with Excel 2003.

    Hope this helps

    Thanks
    Attached Files Attached Files

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    No, have a look in the VBEditor's helpfiles (F1).
    Look for autofilter: you will find everything to pass arguments.

  6. #6
    Registered User
    Join Date
    10-06-2011
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Honestly I tried,

    I can't get past the error. The code is not working. I was able to create this

    Sub CopyRows()
    Dim LR As Long, i As Long, j As Long
    With Sheets("PRIORITY 4")
    LR = .Range("G" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
    If .Range("G" & i).Value = "Closed" Or .Range("G" & i).Value = "Cancelled" Then
    j = j + 1
    .Rows(i).Copy Destination:=Sheets("Closed").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
    Next i
    End With
    MsgBox "Done:" & vbNewLine & j & " rows copied", vbInformation
    End Sub

    This code was borrowed changed as far as i was able to understand and it copies the lines from ones sheet. Can sombody help me and let it look at the other sheets as well, but make it as the suggested code from snb to exlude in stead of include worksheets to look at.
    And to ensure that the sheet is always up to date to clear the sheet but not the headers.

    Thanks

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Hi SuperSman

    Can't help but feel I'm missing something here. The code in the attached copies all rows that has "Closed" or "Canceled" in Status Column G of the PRIORITY worksheets. Each time the code is run it does this
    Keep the first row of the sheet CLOSED the same but clear the rest of the sheet CLOSED at the each run of the macro
    You don't say what you wish to happen to rows on PRIORITY worksheets that have "Closed" or "Cancelled"...so, they're still there.

    The code takes a bit of time to run due to all the Volatile functions. If you can figure a way to avoid them you'll be much happier with the results.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Registered User
    Join Date
    10-06-2011
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    The code works briliant. there is one that would work nice in future. Could the code use an exlusion of sheets in stead of an array. SNB used

    if sh.name<>"closed" then .....
    .

    If a Priority 5 sheet would be added the code does not need updating.

    For now thanks a lot!

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Hi SuperSman

    In snb's code you'd have to exclude also "WAITLIST" and "THESAURUS" and that can be done. Is that how you wish to proceed?

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Hi SuperSman

    Try this
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-06-2011
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Yes that's working perfect. Thanks a million

    I do wish to know what is happening exactly.

    Most of it I can read, but there is one item that I can not find as a variable. The number of columns that will be copied. Does it take into account that some column are hidden?

    Thanks a lot again

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Consolidate rows from multiple worksheets in one based on cell criteria

    Hi SuperSman

    Please Login or Register  to view this content.

+ 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