+ Reply to Thread
Results 1 to 18 of 18

Summarize Multiple Worksheets Based on Criteria

  1. #1
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Summarize Multiple Worksheets Based on Criteria

    Can someone suggest some code for me please as I have virtually no knowledge of VBA and I've been advised that a macro would be the best solution for my problem.

    I want a summary list of data from all columns of worksheets that contain the target data and only where the value in col D is 1. So, in the attached example, the data to be checked is on Sheet1 and Sheet2 and the result should be shown on Summary sheet. There will be some tabs that don't need to be checked for the data so it's not a case of check all other tabs except for Summary.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    Try the attached.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    Quote Originally Posted by AB33 View Post
    Try the attached.
    Thanks for this. I've copied and pasted your code into my actual workbook after making a couple of changes where I thought I should make them but maybe I'm wrong. In the example, the criteria to check is in col D but in my actual workbook it's in col H.

    In your script what do I need to change to the reference column from D to H? Also, each reference worksheet will range from row 2 to row 101.:

    Sub ConsolidateData()
    Dim ws As Worksheet, wsMaster As Worksheet, LR As Long
    Application.ScreenUpdating = 0
    Set wsMaster = Sheets("Summary")
    wsMaster.UsedRange.Offset(1).EntireRow.Clear
    For Each ws In ThisWorkbook.Worksheets
    With ws
    If .Name <> wsMaster.Name And .Name <> "Total" Then
    .AutoFilterMode = False
    .Rows(1).AutoFilter 4, "1"
    LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
    If LR > 1 Then
    .Range("A2:D" & LR).Copy
    wsMaster.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
    End If
    .Rows(1).AutoFilter
    End If
    End With
    Next ws

    Application.ScreenUpdating = True
    End Sub
    Last edited by xybadog; 05-30-2014 at 06:58 AM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    Please Login or Register  to view this content.
    Also the line above end if

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    It almost works but for some reason is stopping at this line
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    .

    I've attached my actual workbook (with generic data) that I've applied the code to.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    I've added the macro to my proper workbook (instead of the example) and it keeps failing at
    Please Login or Register  to view this content.
    I've now attached my actual spreadsheet (with generic data) as I can't see where it's going wrong.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    You want to filer the data by column H and yet, some of the sheets do not have column H.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    I've added some sheets to the exceptions and some sheets I've added a col H where necessary.

    It works, almost, perfectly but, the result is showing the first row of data (row 2) of each tab even if it doesn't have "1" in col H.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    Which sheet from the attached? If the sheet is not on attached, please attach a new one which shows the error.

  10. #10
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    Sorry, now attached. If you look at, for example, record 200, 800, 1000, 1100 etc are showing on the summary even though their value in col H is 0.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    Are you sure you are using the correct code? The old code was attached, but I had attached the amended code.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    It's still showing record 200 which it shouldn't but I can live with this.

    Thanks very much for your help and your patience.


  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    No, which sheet exactly is? Is it sheet 200-299?

  14. #14
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    Yes, sheet 200-299 row 2

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    Sheet 200-299 has column H and there is single row which has a value of 1, so when the code loops through the sheets, it copies that single row in to summary. Or, am I missing something?

  16. #16
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    Sorry took so long to get back but I've been unavailable.

    You are right, there is only a single row (row 83) that has a value of 1 in col H but the first row of data (row 2) on tab 200-299 has a value of 0 in col H and this is showing in the results when it shouldn't. I've not edited the code from your last version and it seems to be showing this error for me. Any record that has "Destroyed See Previous Record" for example, in col D, these all have 0 in col H in their worksheet so don't meet the criteria to be included in the summary.
    Last edited by xybadog; 06-02-2014 at 09:44 AM.

  17. #17
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Summarize Multiple Worksheets Based on Criteria

    Okay! I can now see what is going. The filer data were correct, but the clear data commenced on the wrong row, hence the old wrong data was not deleted.

    Change this line
    Please Login or Register  to view this content.
    Last edited by AB33; 06-02-2014 at 10:39 AM.

  18. #18
    Forum Contributor
    Join Date
    07-02-2012
    Location
    UK
    MS-Off Ver
    365/2008
    Posts
    152

    Re: Summarize Multiple Worksheets Based on Criteria

    This works great. Thanks for all your help.

+ 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. [SOLVED] summarize information based on criteria using excel
    By zhengzhi8806 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-03-2013, 11:42 AM
  2. [SOLVED] Summarize Based on Criteria
    By Kumara_faith in forum Excel General
    Replies: 6
    Last Post: 07-24-2013, 10:39 AM
  3. Replies: 1
    Last Post: 05-13-2013, 09:25 PM
  4. Replies: 8
    Last Post: 10-27-2011, 05:43 PM
  5. Summarize data based on multiple criteria
    By sigil in forum Excel General
    Replies: 3
    Last Post: 01-06-2010, 08:56 PM

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