Find MAX value in multiple dynamic ranges

wdgor

Board Regular
Joined
Jan 21, 2009
Messages
90
Office Version
  1. 365
Platform
  1. Windows
I need to do a check to see if the user enters a date for the children, in the "Target Completion Date", that is greater than the target date of the parent ("Issue No." that is a whole number represents the parent) - the children have a decimal number in the "Issue No." field and the row is colored. The problem is that there is a variable number of potential children and those can happen with any parent, i.e. there may be no children, 1 child, 2 children, 20 children or X Children. I have a formula =COUNT(IF(MOD($4$1:$a$1000,1),A1:A1000)) that will give me a total count of the decimal entries. I can do a MAX value from that but how can I do a MAX value only looking at each parent and associated child or children? Thanks for any assistance.


1654280045544.png
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Here's a couple of ideas you may find useful?

ABCDE
1Issue NoCompletion DateMaxDate
211 May 20222 May 22
31.12 May 2022 
4213 May 202213 May 22
5313 May 202213 May 22
6415 May 202215 May 22
7511 Jun 202215 Jun 22
85.14 Jun 2022 
95.213 Jun 2022 
105.34 Jun 2022 
115.415 Jun 2022 
12620 Jun 202220 Jun 22
Sheet4
Cell Formulas
RangeFormula
E2:E12E2=IF(MOD(A2,1),"",MAX(IF(INT(A$2:A$12)=A2,D$2:D$12)))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D2:D12Expression=D2>VLOOKUP(INT(A2),A$2:D$12,4,)textNO
 
Upvote 0
Stephen - your solution works perfectly for a known populated range - thanks!!!

Here is my problem now. This sheet will continue to be expanded with users entering new lines with parents and children. If I try to extend the range in your formula beyond the last row in "A" and "D" that has a value, I get a #VALUE error. So, I tried the following:

I created a Name to get the Last Row number for Column A (LastRowA with the formula - =SUMPRODUCT(MAX(('Master Worksheet'!$A:$A<>"")*(ROW('Master Worksheet'!$A:$A)))) - this formula works on its own but slows down the sheet computation - and also one for Column P (in your example that would be col. D) - =SUMPRODUCT(MAX(('Master Worksheet'!$P:$P<>"")*(ROW('Master Worksheet'!$P:$P)))). Then I modified your formula - =IF(MOD(A4,1),"",MAX(IF(INT(A$4:LastRowA)=A4,P$4:LastRowP))) and I get a #VALUE error. I don't know if using "A$4:LastRowA" is a legitimate range designator. I tried searching around to see how I can build an expression that can be used in your formula to look at Row A and P that takes into consideration the last row with a value in each column. I tried a few things with no success. Any thoughts on that? Thanks again for your assistance.
 
Upvote 0
I realized that my formula didn't have the column designator so I tried: =IF(MOD(A4,1),"",MAX(IF(INT(A$4:A&"$"&LastRowA)=A4,P$4:P&"$"&LastRowP))).. That gave me a #NAME error. I thought it would evaluate to get the last row from LastRowA and LastRowP and concatenate that with the column, i.e. A$16 and P$16 as 16 is the last row in my test sheet. I can't figure out how to get the last row in the formula. I need an expression to get: (INT(A$4:A$last row). Driving me nuts!
 
Upvote 0
Perhaps:

ABCDE
1Issue NoCompletion DateMaxDate
211 May 20222 May 2022
31.12 May 2022 
4213 May 202213 May 2022
5313 May 202213 May 2022
6415 May 202215 May 2022
7511 Jun 202215 Jun 2022
85.14 Jun 2022 
95.213 Jun 2022 
105.34 Jun 2022 
115.415 Jun 2022 
12620 Jun 202220 Jun 2022
Sheet1
Cell Formulas
RangeFormula
E2:E12E2=IF(MOD(A2,1),"",MAX(IF(INT(IssueNo)=A2,CompletionDate)))
Named Ranges
NameRefers ToCells
CompletionDate=Sheet1!$D$2:INDEX(Sheet1!$D:$D,LastRow)E2:E12
IssueNo=Sheet1!$A$2:INDEX(Sheet1!$A:$A,LastRow)E2:E12
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D2:D12Expression=D2>INDEX(CompletionDate,MATCH(INT(A2),IssueNo))textNO

LastRow: =COUNTA(Sheet1!$A:$A)-COUNTA(INDEX(Sheet1!$A:$A,1):Sheet1!$A$2)+ROW(Sheet1!$A$2)

You could also use the simpler, but less robust, construction LastRow: =COUNTA(Sheet1!$A:$A)
 
Upvote 0
Solution
Thank you for your suggestion. However, when I apply it, I get a #VALUE error.

I used XL2bb to capture the sheet but it is not showing all the Named Ranges.

This is the LastRow =COUNTA('Master Worksheet'!$A:$A)-COUNTA(INDEX('Master Worksheet'!$A:$A,1):'Master Worksheet'!$A$4)+ROW('Master Worksheet'!$A$4)
This is the LastRowA1(your Issue No) ='Master Worksheet'!$A$4:INDEX('Master Worksheet'!$A:$A,LastRow)
This is the LastRowP1 (your Completion Date) ='Master Sheet'!$P$4:INDEX(Sheet1!$P:$P,LastRow)

This is the formula in Column R =SUMPRODUCT(MAX(($A:$A<>"")*(ROW(A:A))))

Services Master List 2022_Example_dynamic_range2.xlsm
ABCDEFGHIJKLMNOPQR
3Issue No. (Do Not Modify)Task NumberClient (Required) Select only one ClientDivision (Multiple Selections Allowed)DevOps TicketZOHO TicketHelp Desk SLAType (Required)Module (Required) - Multiple Selections AllowedIssue DateDescriptionCreated ByIssue OwnerPriorityTarget Start DateTarget Completion DateMaximum Target Completion DateColumn1
411CCHMCCCHMCAllIssueProduct6/2/20226/3/2022#VALUE!16
51.11.1CCHMCCCHMCAllIssueProduct6/2/20226/6/2022 16
622CCHMCCCHMCBugRoot Cause Analysis#VALUE!16
733DIV LIRRDIV LIRRFeature RequestAll#VALUE!16
844CCHMCCCHMCRoom Hold Schedule, Add Clinic, Cancel Clinic#VALUE!16
955DIV LIRRDIV LIRR6/2/20226/8/2022#VALUE!16
105.15.1DIV LIRRDIV LIRR6/2/20227/4/2022 16
1166CCHMCCCHMC#VALUE!16
1277MTA - JSSMTA - JSS6/3/20226/9/2022#VALUE!16
137.17.1MTA - JSSMTA - JSS6/4/20226/11/2022 16
1488CCHMCCCHMCAll6/2/20226/8/2022#VALUE!16
158.18.1CCHMCCCHMCAll6/2/20226/9/2022 16
168.28.2CCHMCCCHMCAll6/2/20226/11/2022 16
17  #VALUE!16
18  #VALUE!16
19  #VALUE!16
20  #VALUE!16
21  #VALUE!16
Master Worksheet
Cell Formulas
RangeFormula
Q4:Q21Q4=IF(MOD(A4,1),"",MAX(IF(INT(LastRowA1)=A4,LastRowP1)))
R4:R21R4=SUMPRODUCT(MAX(($A:$A<>"")*(ROW(A:A))))
A6A6=IF(C6="","",IF((OR(A4="",A4="*")),A3+1,A4+1))
A7:A9,A20:A21A7=IF(C7="","",IF((OR(A6="",A6="*")),A4+1,A6+1))
A11A11=IF(C11="","",IF((OR(A9="",A9="*")),A7+1,A9+1))
A12A12=IF(C12="","",IF((OR(A11="",A11="*")),A8+1,A11+1))
A14A14=IF(C14="","",IF((OR(A12="",A12="*")),A9+1,A12+1))
B4:B21B4=[@[Issue No. (Do Not Modify)]]&[@[Client (Required) Select only one Client]]
A17A17=IF(C17="","",IF((OR(A14="",A14="*")),A11+1,A14+1))
A18A18=IF(C18="","",IF((OR(A17="",A17="*")),A12+1,A17+1))
A19A19=IF(C19="","",IF((OR(A18="",A18="*")),A14+1,A18+1))
Named Ranges
NameRefers ToCells
'Master Worksheet'!_FilterDatabase='Master Worksheet'!$A$3:$AH$5000Q14, Q6:Q9, Q11:Q12, A6
LastRowA1='Master Worksheet'!$A$4:INDEX('Master Worksheet'!$A:$A,LastRow)B4, Q5:Q21
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G4:G5000Cell Value="Minor"textNO
G4:G5000Cell Value="Major"textNO
G4:G5000Cell Value="Critical"textNO
C4:C5000Expression=C4=""textNO
I4:I5000Expression=AND(A4<>"",I4="")textNO
H4:H5,H6:I5000Expression=AND(A4<>"",H4="")textNO
E86:F3005,G86:I5000,J86:S3005,A51:D5000,E18:S85,I18:I5000,C18:D50,T17:T5000,U17:AD3005,C17:S17,A17:B50,AF4:AH3005,A5:AD16,A4:P4,S4:AD4Expression=$A4="*"textNO
Cells with Data Validation
CellAllowCriteria
N4:N21List=OFFSET(Setup!$K$3:$K$383,0,0,COUNTIF(Setup!$K:$K,"<>"))
C4:C5000List=OFFSET(Setup!$Q$3:$Q$386,0,0,COUNTIF(Setup!$Q:$Q,"<>"))
D4:D5000List=OFFSET(Setup!$Q$2,1,MATCH($C4,Setup!$Q$2:$X$2,0)-1,COUNTA(OFFSET(Setup!$Q$2,1,MATCH($C4,Setup!$Q$2:$X$2,0)-1,100)),1)
G4:G5000List=OFFSET(Setup!$AD$3:$AD$383,0,0,COUNTIF(Setup!$AD:$AD,"<>"))
H4:H5000List=OFFSET(Setup!$H$3:$H$383,0,0,COUNTIF(Setup!$H:$H,"<>"))
I4:I5000List=OFFSET(Setup!$A$2,1,MATCH($C4,Setup!$A$2:$X$2,0)-1,COUNTA(OFFSET(Setup!$A$2,1,MATCH($C4,Setup!$A$2:$G$2,0)-1,100)),1)
 
Upvote 0
OK, dumb mistake. I was relooking at the Named Ranges LastRowP1 and found a typo "Master Sheet" needs to be "Master Worksheet".

However, when I add a new row, it no longer adds increments the number in column A (I would expet a 9 in column A). That makes absolutely no sense to me as those columns were not touched with the MAX work we have been doing. I am at a loss.

Services Master List 2022_Example_dynamic_range2.xlsm
ABCDEFGHIJKLMNOPQR
3Issue No. (Do Not Modify)Task NumberClient (Required) Select only one ClientDivision (Multiple Selections Allowed)DevOps TicketZOHO TicketHelp Desk SLAType (Required)Module (Required) - Multiple Selections AllowedIssue DateDescriptionCreated ByIssue OwnerPriorityTarget Start DateTarget Completion DateMaximum Target Completion DateColumn1
411CCHMCCCHMCAllIssueProduct6/2/20226/3/20226/6/202216
51.11.1CCHMCCCHMCAllIssueProduct6/2/20226/6/2022 16
622CCHMCCCHMCBugRoot Cause Analysis1/0/190016
733DIV LIRRDIV LIRRFeature RequestAll1/0/190016
844CCHMCCCHMCRoom Hold Schedule, Add Clinic, Cancel Clinic1/0/190016
955DIV LIRRDIV LIRR6/2/20226/8/20227/4/202216
105.15.1DIV LIRRDIV LIRR6/2/20227/4/2022 16
1166CCHMCCCHMC1/0/190016
1277MTA - JSSMTA - JSS6/3/20226/9/20226/11/202216
137.17.1MTA - JSSMTA - JSS6/4/20226/11/2022 16
1488CCHMCCCHMCAll6/2/20226/8/20226/11/202216
158.18.1CCHMCCCHMCAll6/2/20226/9/2022 16
168.28.2CCHMCCCHMCAll6/2/20226/11/2022 16
17  CCHMCAdd Clinic#VALUE!16
18  #VALUE!16
19  #VALUE!16
20  #VALUE!16
21  #VALUE!16
Master Worksheet
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G4:G5000Cell Value="Minor"textNO
G4:G5000Cell Value="Major"textNO
G4:G5000Cell Value="Critical"textNO
C4:C5000Expression=C4=""textNO
I4:I5000Expression=AND(A4<>"",I4="")textNO
H4:H5,H6:I5000Expression=AND(A4<>"",H4="")textNO
E86:F3005,G86:I5000,J86:S3005,A51:D5000,E18:S85,I18:I5000,C18:D50,T17:T5000,U17:AD3005,C17:S17,A17:B50,AF4:AH3005,A5:AD16,A4:P4,S4:AD4Expression=$A4="*"textNO
 
Upvote 0
OK - I took a "clean" test sheet and reproduced all the Name Ranges and formulas as you suggested.

I substituted =SUMPRODUCT(MAX(('Master Worksheet'!$A:$A<>"")*(ROW('Master Worksheet'!$A:$A)))) for =COUNTA('Master Worksheet'!$A:$A)-COUNTA(INDEX('Master Worksheet'!$A:$A,1):'Master Worksheet'!$A$2)+ROW('Master Worksheet'!$A$2) as the COUNTA function didn't work (all cells were blank). I suspect that is because there are formulas in all the rows in column A and COUNTA thinks they are populated. The SUMPRODUCT command took care of that.

So, IT WORKED. However, it takes an inordinate amount of time to calculate the sheet even with one additional row added (took 77 seconds), i.e. the user wouldn't have the patience to wait for the calculation to complete and neither would I. Any thoughts on being able to speed it up?
 
Upvote 0
Stephen - I think we got it!! I changed the LastRow Named Range to =MATCH(MAX('Master Worksheet'!$A:$A)+1,'Master Worksheet'!$A:$A) and it works correctly and fast.

Thank you for all your expert assistance. I would have been scratching my head for a long time without your help.
 
Upvote 0
Well done for figuring it out. I'm glad we could point you in the general direction.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,684
Members
449,116
Latest member
HypnoFant

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