Formula errors when nested into larger formula but not when calculated alone?

jhall_cb

New Member
Joined
Jul 14, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Please god someone give me some ideas because at the moment it looks like Excel is just screwing with me...

I haven't posted on this account before but no stranger to Excel, VBA or Formulas. Running Windows 10, Office 365. So, I have a biiig horrible formula with lots of things nested all over the place (See the horrendous code tag at the bottom of the post). Within said beast is the nested formula:
Excel Formula:
OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F20,,1)),4),"1","")&MATCH(OFFSET(F20,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F20,,-1))-1)=0
which produces a #VALUE error. Evaluating the first section produces a single cell offset range with a value of 0:
Excel Formula:
{0}=0
. Evaluating this returns TRUE, happy days. So why does the whole section error? I have tried checking data types, checking for text, wrapping both in a NUMBERVALUE function, all still error as a group but evaluate separately as expected.

To compound my confusion even further if I copy the above formula from its enormous nested parent and run in a separate cell it returns TRUE as it should in the cell value but returns a #VALUE error on the formula bar evaluation??

Goal is to return a Boolean TRUE/FALSE for a complex conditional formatting rule. Minisheet below of the data in question below, based on a PivotTable. Any ideas would be greatly appreciated.

Parent Formula:
Excel Formula:
=IF(AND(F3<>0,OFFSET(F3,-1,)<>F3),IF(COUNTIFS(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,3)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),"<7")<=2,OR(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),1),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),2)),IF(COUNTIFS(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,3)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),"<7")<=3,OR(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),1),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),2),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),3)),IF(COUNTIFS(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,3)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1),"<7")<=4,OR(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),1),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),2),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),3),OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))=SMALL(IF(OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,1)),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)=0,OFFSET(INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(OFFSET(F3,,COLUMN($K$2)-COLUMN(F3))),4),"1",0)&MATCH(OFFSET(F3,,-1),E$1:E$372,0)),1,,COUNTIF(E$1:E$372,OFFSET(F3,,-1))-1)),4)),FALSE))),FALSE)

Minisheet:
OrgMapping Simulator 2.xlsm
EFGHIJK
1
2L4L5L6L7L8L9Sum of Headcount
30
40
50
60
70
82
90
100
110
12H&G UK - HR - Employee Development BL - 2270339170
13H&G UK - HR - Employee Development Team - 2270339150
14H&G UK - HR - Employee Development Team - 227033915H&G UK - HR - CIS & EOS Development - 2270462800
15H&G UK - HR - Employee Development Team - 227033915H&G UK - HR - Employee Development Compliance - 2280805400
16H&G UK - HR - Employee Development Team - 227033915H&G UK - HR - Employee Development Trainers - 2280805380
175
180
19H&G UK - HR - Lynne Oates - 2280901430
20H&G UK - HR - Lynne Oates - 228090143LHR HR-BP - 2270339142
21H&G UK - HR - Roshnee Khandelwal - 2280901390
22H&G UK - HR - Roshnee Khandelwal - 228090139EMA HR Services - 2270339162
23H&G UK - HR - Roshnee Khandelwal - 228090139H&G UK - HR - EMA HR - 2280805464
24H&G UK - HR - Roshnee Khandelwal - 228090139HR Admin & Passes - 2280805475
25H&G UK - HR - Roshnee Khandelwal - 228090139HR Dept. Occ Health BL - 2270339100
26H&G UK - HR - Rowena Catling - 2280901420
27H&G UK - HR - Rowena Catling - 228090142HR Recruitment - 2280806604
280
Piviot
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B3:J502Expression=AND(MOD($A3+1,2)=0,B3=B2,ROW()<MATCH("Grand Total",$B:$B,0))textNO
B3:J502Expression=MOD($A3+1,2)=0textNO
K3:K373Expression=MOD($A3+1,2)=0textNO
B3:J502Expression=AND(MOD($A3,2)=0,B3=B2,ROW()<MATCH("Grand Total",$B:$B,0))textNO
B3:J502Expression=MOD($A3,2)=0textNO
K3:K373Expression=MOD($A3,2)=0textNO
 

Attachments

  • 1657824394245.png
    1657824394245.png
    202.4 KB · Views: 8

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Only lightly tested, but I think it works:

ABCDEFGHI
1MinN7Level
25
3Level 1Level 2Level 3Level 4Level 5TypeResponsesCheckCell
4TOPParent99FALSE
5TOPAParent38FALSE
6TOPAA.1Parent21FALSE
7TOPAA.1A.1.1Parent21FALSE
8TOPAA.1A.1.1A.1.1.1Child10FALSE
9TOPAA.1A.1.1A.1.1.2Child10TRUE
10TOPAA.1A.1.1A.1.1.3Child1TRUE
11TOPAA.2Parent17FALSE
12TOPAA.2A.2.1Parent2FALSE
13TOPAA.2A.2.1A2.1.1Child2TRUE
14TOPAA.2A2.2Parent15FALSE
15TOPAA.2A2.2A.2.1.2Child10TRUE
16TOPAA.2A2.2A,2.1.3Child5TRUE
17TOPBParent58FALSE
18TOPBB.1Parent42FALSE
19TOPBB.1B1.1Parent30FALSE
20TOPBB.1B1.1B1.1.1Child10FALSE
21TOPBB.1B1.1B1.1.2Child10FALSE
22TOPBB.1B1.1B1.1.3Child10FALSE
23TOPBB.1B1.2Parent12FALSE
24TOPBB.1B1.2B1.2.1Child12FALSE
25TOPBB.2Parent6FALSE
26TOPBB.2B2.1Parent6FALSE
27TOPBB.2B2.1B2.1.1Child6TRUE
28TOPBB.3Parent10FALSE
29TOPBB.3B3.1Parent10FALSE
30TOPBB.3B3.1B3.1.1Child10FALSE
31TOPCParent3FALSE
32TOPCC.1Parent3FALSE
33TOPCC.1C1.1Parent3FALSE
34TOPCC.1C1.1C1.1.1Child3TRUE
35
Sheet1
Cell Formulas
RangeFormula
I4:I34I4=CheckCell($A$4:$G$34,MinN,I$2,ROWS(I$4:I4))
Named Ranges
NameRefers ToCells
MinN=Sheet5!$F$1I4:I34
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I4:J34Cell Value=TRUEtextNO
A4:J34Expression=COUNTBLANK($A4:$G4)=COLUMNS($A4:$G4)-2-$I$2textNO


CheckCell: =LAMBDA(data,MinN,Level,RowNo,LET(cols,COLUMNS(data),r,INDEX(data,RowNo,),No,IF((BYROW(data,LAMBDA(r,COUNTBLANK(r)))=cols-2-Level)*BYROW(INDEX(data,,1):INDEX(data,,Level-1)=INDEX(r,1):INDEX(r,Level-1),LAMBDA(rw,AND(rw))),(INDEX(data,,cols)-SEQUENCE(ROWS(data))/10000)),s,SUM((No>0)*(No<=MinN-1)),IF(s>0,INDEX(No,RowNo)<=IFERROR(SMALL(No,s+(s=1)),MIN(No)))))

I've conditionally formatted to show the level being tested, to make it easier to visualise.

With 365's functionality (e.g. using Lambda and Let) you simply need to point to your actual data range, and the formula will adjust. It's not as horrible a formula as the original, but you may still need to get your head around the new functions.
 
Upvote 0
Solution
Hi Stephen,

My apologies for the delayed response.

The above looks great and need to start getting into some of the newer functions like LAMBDA anyway so a good chance to do it. Thank you for taking the time to understand the problem and propose a solution - Marked as solution.

I'm still curious on the evaluation error as I had always assumed that calculation would be the same in a cell to the formula bar but obviously not. Thanks again, I'll post the full solution when I can get back to that job.
 
Upvote 0
I'm still curious on the evaluation error ....
Ha ha, yes, I dodged the actual question.

Based on your formula in Post #1, I suggest you have a have a look at E1:E372. Are there error values anywhere in this range?
 
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,873
Members
449,192
Latest member
MoonDancer

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