Conditional Formatting with multiple criteria

Katherine1

New Member
Joined
Oct 4, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
The document I have is several thousand rows long and by about 130 columns. I need to determine the latest load date for each Item number.

Based on the item # in Column B, I would like to highlight the current Item #, (Column C; Y = Yes) with the latest Load date in Column D. In several cases, an item # may have multiple load dates that appear to be current. Items have varying numbers of rows so multiple rows will need to be highlighted for each item.

1633387484513.png

Thank you in advance for your help!

Katherine
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Date and time field.xlsx
ABCD
1Submission OrderItem NumberCurrent Y/NLoad Date
211Y9/30/2021
321Y10/2/2021
434Y10/2/2021
545Y10/2/2021
653N10/1/2021
763N10/2/2021
874N10/4/2021
982N10/4/2021
1093Y9/30/2021
11103Y10/1/2021
12115N10/3/2021
13122Y10/1/2021
14133Y10/1/2021
15142N10/3/2021
16154N10/2/2021
17165Y9/30/2021
18172N10/2/2021
19183N10/4/2021
20195Y10/2/2021
21204N10/1/2021
22214Y10/4/2021
23222Y9/30/2021
24233Y10/2/2021
25241N10/1/2021
26252N10/1/2021
Sheet3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:D26Expression=AND($D2=MAX(($B$2:$B$26=$B2)*($C$2:$C$26="Y")*($D$2:$D$26)), $C2="Y")textNO
 
Upvote 0
Solution
This maybe?
Blank - Copy.xlsx
ABCD
1Data example
2Submission OrderItem NumberCurrent Y/NLoad Date
31MMS3Y9/28/21 15:32
41MMS3Y9/28/21 15:32
51MMS3Y9/28/21 15:32
61MMS3Y9/28/21 15:32
71MMS3Y9/28/21 15:32
82P653Y9/28/21 16:01
92P653Y9/28/21 16:01
102P653Y9/28/21 16:01
112P653Y9/28/21 16:01
122P653N9/28/21 16:01
132P653N9/28/21 16:01
142P653N9/28/21 16:01
153P656Y9/28/21 16:01
163P656Y9/28/21 16:01
173P656Y9/28/21 16:01
183P656Y9/28/21 16:01
193P656Y9/28/21 16:01
203P656Y9/28/21 16:01
214MMS3Y10/1/21 14:37
224MMS3Y10/1/21 14:37
234MMS3Y10/1/21 14:37
244MMS3Y10/1/21 14:37
254MMS3Y10/1/21 14:37
265P653N9/28/21 16:21
275P653N9/28/21 16:21
285P653N9/28/21 16:21
295P653N9/28/21 16:21
306P653Y10/1/21 14:37
316P653Y10/1/21 14:37
326P653Y10/1/21 14:37
336P653Y10/1/21 14:37
347P656Y10/1/21 14:37
357P656Y10/1/21 14:37
367P656Y10/1/21 14:37
377P656Y10/1/21 14:37
Sheet1 (2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A3:D37Expression=AND($D3=MAX($D$3:$D$37),$C3="Y")textNO
 
Upvote 0
This maybe?
Nope! Sorry about that, @JGordon11 . (I guess it should have been bluntly obvious for me . . . I didn't even have column B in my formula.) Mine happened to work on the given data, but failed as soon as I intentionally broken it:
Blank - Copy.xlsx
ABCDEFGHIJ
1Data exampleExpected results
2Submission OrderItem NumberCurrent Y/NLoad DateSubmission OrderItem NumberCurrent Y/NLoad Date
31MMS3Y9/28/21 15:321MMS3Y9/28/21 15:32
41MMS3Y9/28/21 15:321MMS3Y9/28/21 15:32
51MMS3Y9/28/21 15:321MMS3Y9/28/21 15:32
61MMS3Y9/28/21 15:321MMS3Y9/28/21 15:32
71MMS3Y9/28/21 15:321MMS3Y9/28/21 15:32
82P653Y9/28/21 16:012P653Y9/28/21 16:01
92P653Y9/28/21 16:012P653Y9/28/21 16:01
102P653Y9/28/21 16:012P653Y9/28/21 16:01
112P653Y9/28/21 16:012P653Y9/28/21 16:01
122P653N9/28/21 16:012P653N9/28/21 16:01
132P653N9/28/21 16:012P653N9/28/21 16:01
142P653N9/28/21 16:012P653N9/28/21 16:01
153P65633Y9/28/21 16:013P656Y9/28/21 16:01
163P656Y9/28/21 16:013P656Y9/28/21 16:01
173P656Y9/28/21 16:013P656Y9/28/21 16:01
183P656Y9/28/21 16:013P656Y9/28/21 16:01
193P656Y9/28/21 16:013P656Y9/28/21 16:01
203P656Y9/28/21 16:013P656Y9/28/21 16:01
214MMS3Y10/1/21 14:374MMS3Y10/1/21 14:37
224MMS3Y10/1/21 14:374MMS3Y10/1/21 14:37
234MMS3Y10/1/21 14:374MMS3Y10/1/21 14:37
244MMS3Y10/1/21 14:374MMS3Y10/1/21 14:37
254MMS3Y10/1/21 14:374MMS3Y10/1/21 14:37
265P653N9/28/21 16:215P653N9/28/21 16:21
275P653N9/28/21 16:215P653N9/28/21 16:21
285P653N9/28/21 16:215P653N9/28/21 16:21
295P653N9/28/21 16:215P653N9/28/21 16:21
306P653Y10/1/21 14:376P653Y10/1/21 14:37
316P653Y10/1/21 14:376P653Y10/1/21 14:37
326P653Y10/1/21 14:376P653Y10/1/21 14:37
336P653Y10/1/21 14:376P653Y10/1/21 14:37
347P656Y10/1/21 14:377P656Y10/1/21 14:37
357P656Y10/1/21 14:377P656Y10/1/21 14:37
367P656Y10/1/21 14:377P656Y10/1/21 14:37
377P656Y10/1/21 14:377P656Y10/1/21 14:37
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G3:J37Expression=AND($D3=MAX(($B$3:$B$37=$B3)*($C$3:$C$37="Y")*($D$3:$D$37)), $C3="Y")textNO
A3:D37Expression=AND($D3=MAX($D$3:$D$37),$C3="Y")textNO


How does that formula work? Can you break it down for us?
 
Upvote 0
Inside the max function I am multiplying three arrays: 1) True or false (1 or 0) do the cells in column B equal the cell in Column B current row, 2) True or false (1 or 0) do the cells in column C equal "Y", and 3) the date values in Column D. This returns an array of zeroes and date values matching the criteria. Then Max returns a single value, the latest date in the array. $D3=Max returns true if the date in the current row matches the max. Then we also want to exclude rows where the C column is not "Y" (because there could be some rows with N in col C but the date equals the max, so use the And function. That then returns true only for rows meeting the criteria. It is important where the $ signs are applied to lock the column but not the row of the single cell references.
 
Upvote 0
@JGordon11 - Thank you for the formula and explanation. This formula does works just like I asked. My only issue is that with 231,555 rows my Excel takes quite a bit of time to complete. I was able to divide the rows and do this in 3 stages to help with the timing.

Thanks again!
 
Upvote 0
Conditional formatting 230k+ rows is probably not the best solution.

Another option would be to use Power Query to create a table of just the item numbers with Current = Y and the latest load date. You would need to have your data in the form of a formal excel table and could use M code similar to this (which assumes your table is called Table1):

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"Submission Order", Int64.Type}, {"Item Number", type text}, {"Current Y/N", type text}, {"Load Date", type datetime}}),
    FilterRows = Table.SelectRows(ChangeType, each ([#"Current Y/N"] = "Y")),
    GroupRows = Table.Group(FilterRows, {"Item Number"}, {{"Load Date", each List.Max([Load Date]), type nullable datetime}, {"Details", each _, type table }}),
    AddCustom = Table.AddColumn(GroupRows, "Submission Order", each Table.SelectRows(_[Details], (x) =>  x[Load Date] =_[Load Date])[Submission Order]{0}),
    ReorderColumns = Table.RemoveColumns(Table.ReorderColumns(AddCustom,{"Submission Order", "Item Number", "Load Date"}),{"Details"})
in
    ReorderColumns

If you load the resulting table to the workbook (preferably to its own sheet) then you can right click anywhere in the table and click refresh when the data changes. It won't be a computational performance drag except when it refreshes. This could be made to be dynamic with an event driven VBA macro but I don't recommend it.

Yet another option would be a VBA macro to either build the same table as the Power Query approach did, or to highlight the existing table. Both of these VBA approaches can be written to run very fast. Like the PQ approach they would be manually refreshed when the data changes, but could be made to be dynamic if needed (I would not recommend making it dynamic unless there's a compelling reason to).
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top