+ Reply to Thread
Results 1 to 17 of 17

Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

  1. #1
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Hi,
    I need some help please to be able to quickly sort a table on "Date / Time" and (firstly) another column (F1). Then I need to have the T3Fn columns of F1 (for each unique Date / Time) filled with the percentage values for the Date/Time/F1 data set.
    (See attached file).
    It would be extremely useful if the unique "Date/Time/F1" and the new column "Date/Time/T3F1"set of data could be conditionally coloured with Red to Green scale.

    After the Date/Time/F1 sort, I then need to sort table on Date/Time/F2.

    Again, it would be extremely useful if the data could be conditionally coloured with Red to Green scale.

    I need to repeat this for F3 and F4 also.

    This takes too long to do manually and I've looked at trying Index/Match in formulas but can't get my head around it.

    I tried recording macros but can't seem to get anything working since the ranges are dynamic owing to the filters.

    I'm sure it just needs a VBA that loops on each filter but my VBA skills are minimal.

    Any help would be gratefully received.
    Attached Files Attached Files
    Last edited by margetc; 04-10-2018 at 03:09 PM. Reason: change calculations to percentages

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    First of all, thanks for putting the data into an Excel Table.

    I added a helper column to computer the Date/Time.

    Then I built a Pivot table to get me a unique list of date times on sheet2. I added formulas to the right of these dates to compute the 1st, 2nd and 3rd place for that date time using MAX and LARGE in array formulas.

    I overlaid the whole mess with a named dynamic range called L_Date_Time. I use this to do VLookups for 1st, 2nd and 3rd place in an if statement in the original table.

    Since we are using an Excel Table, when you add or copy in data, the formula for the helper column is remembered and copied down automatically as are all the formulas. The pivot table may have to be refreshed.

    I extended the formulas down to Row 102 on sheet 2 - if you have more data, extend them further.

    I did find two cells in the original data where there was an error value in the cells. This put an error value in my formulas. I hunted these down and deleted their contents.

    I only spot checked a few of these. To paraphrase my old math textbooks, "QA is left as an exercise for the reader."

    I am assuming that you want the conditional formatting applied within each Date/Time and not across the entire column. I'll tackle that next.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    You could use a COUNTIFS formula to rank each "F" value for a given Date-Time. Then use conditional formatting to highlight all the 1s, 2s, and 3s.

    Put this formula in Cell H2 and copy down
    =COUNTIFS([Date],A2,[Time],B2,[F1],">="&D2)

    Change the [F1] and D2 for the other rank columns.

    Apply CF rules to highlight all the 1s=green, 2s=Yellow, and 3s=red.
    Alternatively, you could apply a Green-Red color scale to each of the ranked columns.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    The conditional formatting will have to be handled with VB code. I can define an array formula or offsets for a dynamic range in the conditional formatting if the CF is based on formulas. However, I can't define a color range. Those CFs that use a color range won't allow dynamic ranges.

    I don't like what I am seeing: defining one conditional format for each unique time slot times 4. These will have to be cleared (without disturbing the other CF on the sheet) and re-established whenever new data is applied to the sheet.

    I can do this, but I don't like using a sledgehammer if an more elegant solution is available.

  5. #5
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Hi DFLAK,
    Thank you very much for the solution.
    I was in the process of modifying the original requirement when your solution came through.
    I never thought about creating another table with a pivot table index column - thanks, I've learned something new.

    My modified requirement is a little more complex as it requires each cell in the T3Fn columns to be populated with its respective percentage value for the Date/Time/Fn range it refers to. This means the new table on sheet 2 would need variable amounts of columns.

    Don't worry if the revised requirement is not achievable - I should be able to get by with what you have done so far as it is quicker than what I was doing. But if you do have any thoughts on the revised "percentage" requirement I would be grateful to receive them.
    Thanks again for the solution AND for the detailed explanation.

    Let me know if you don't think the percentage request is possible as I will close this thread and start a new one.

  6. #6
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Quote Originally Posted by AlphaFrog View Post
    You could use a COUNTIFS formula to rank each "F" value for a given Date-Time.
    Hi AlphaFrog,
    Thanks for the suggestion. It looks like a good place to start. I've not come across COUNTIFS before. I like the idea and it will give me something to play around with.
    I'm thinking there may be a way to adapt your suggestion to work out the relative percentages of the F1/F2/F3/F4 columns and insert the percent value in the T3F1/2/3/4 columns rather than the RANKs.
    Thanks again.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Quote Originally Posted by margetc View Post
    Hi AlphaFrog,
    Thanks for the suggestion. It looks like a good place to start. I've not come across COUNTIFS before. I like the idea and it will give me something to play around with.
    I'm thinking there may be a way to adapt your suggestion to work out the relative percentages of the F1/F2/F3/F4 columns and insert the percent value in the T3F1/2/3/4 columns rather than the RANKs.
    Thanks again.
    Use SUMIFS instead...

    =D2/SUMIFS([F1],[Date],A2,[Time],B2)

  8. #8
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Super. Thanks.

  9. #9
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Hi AlphaFrog,
    Not sure if it is correct to continue here or to start a new thread.
    I need to be able to quickly ConditionColour the percentages in columns T3F1/2/3/4 based on the unique Date/Time set of data.

    I managed to make a macro but its not very neat as it relies on me selecting the first cell of the required range (eg H2 for the 28/3/18 + 14:00 range)
    The table needs to be initially sorted by Date/Time.

    Problems:
    1. This does not colour code all the Date/Time set of data.
    2. This will include part of the next data set if there are less than 10 rows in the data set.

    It would be better for a macro to find the first unique Date/Time then colour the T3F1/2/3/4 columns.
    Then find the next unique Date/Time and then colour the T3F1/2/3/4 columns. etc.

    I tried to find the COUNTIIF for Date/Time and use this to select the rows to colourcode but I couldn't get it to work.
    Any help would be appreciated.
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Hi AlphaFrog,
    Thanks for the code.
    I think I understand the operation (finding each unique Date/Time plus T3Fn column and looping to format each array of unique Date/Time/T3Fn data).
    However, I've hit a wall because I get an error 429 "active x cant create component With CreateObject Scripting.Dictionary".
    I've googled a bit and it would seem that my Mac Office 356 Excel does not work the same as Win Excel.

    Copied from internet.
    " Mac OS does not have the Scripting Runtime library, so none of those things will be available to you -- Dictionary, FileSystemObject, etc.
    You'll need to use a Collection or other data type in lieu of Dictionary type,"

    I've no idea what this means.
    Do you have any suggestions?

    Thanks for your help.

  12. #12
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Please Login or Register  to view this content.
    Last edited by margetc; 04-12-2018 at 12:45 PM. Reason: adding code

  13. #13
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Yeah. The method I used (the Scripting Dictionary) is not available on a Mac. I'll take another stab at it tonight.

    1.) Change your profile to indicate you're using Office 365 Mac

    2.) In future postings, also indicate that you have a Mac in your question. It may prevent redundant coding.

    3.) Your Date and Time values in your example workbook are wonkie. The dates are serial dates, but the time values are just Text (not serial time values). That has an effect on how the macro is coded. If you don't know how Excel stores Date-Time values, read the link. Before re-coding the macro, I need to know is this the way your actual data will be or is this an anomaly in the example file? It would be better if the time values were serial-time values and not text, but I can work around it. Also, It would be a little easier to group the data if the date and time values were combined in one column. So explain how the data is entered or imported. What is the source? Can you combine the two in one column?

  14. #14
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Hi AlphaFrog,
    My apologies for not being explicit about my Excel version - I have added it to my profile now.

    The thread I read about the Dictionary is... stackoverflow.com/questions/43738332/activex-component-can-t-create-object-excel-for-mac. Not sure if it's of use for my problem.

    Regarding the Date and Time values: The date arrives like this. Unfortunately I have no control of the formats.
    However, the file is not used elsewhere so you can modify the formats and/or add a new column to combine the Date/Time whichever way makes it easier.
    Thanks again, and apologies for the Mac oversight.

  15. #15
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Hi AlphaFrog,
    Not sure if this is of use but after a bit more googling I amended some of the code and got past some of the error messages but still getting errors.
    I'm just stabbing in the dark though as I don't understand vba other than the simple stuff.

    Please Login or Register  to view this content.

  16. #16
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    05-26-2011
    Location
    Cornwall, England
    MS-Off Ver
    Excel for Mac Office 365
    Posts
    27

    Re: Filter data by Columns (a,b,c etc) and mark the top 3 items for each filter.

    Super. Thank you so much. It works like a dream.

+ 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] filter items from 2 columns
    By royalB in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-08-2014, 10:17 AM
  2. [SOLVED] I need formula or macro to filter a number of items from different tables at single filter
    By Karthikeyannb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-05-2014, 11:04 AM
  3. Replies: 6
    Last Post: 10-16-2014, 08:42 AM
  4. [SOLVED] No items displaying in Data Filter at all
    By WISEKATTY in forum Excel General
    Replies: 2
    Last Post: 02-06-2014, 06:58 PM
  5. Change Pivot table Filter Based on Cell Value *Multiple Filter items* Possible?
    By Flydd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2012, 06:57 AM
  6. Adding like items from data filter
    By michaelk68 in forum Excel General
    Replies: 2
    Last Post: 09-04-2008, 10:27 AM
  7. Extract filter items from Drop-Down Automatic Filter
    By karpatov in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2006, 02:10 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