Tarkemelion
New Member
- Joined
- Jun 28, 2022
- Messages
- 21
- Office Version
- 365
- Platform
- Windows
Hi All,
I've been trying to create a numbering formula in one cell which can instantly itemise a schedule of items just by dragging and copying down said formula. However, it is quite complex (read janky) and I'm sure there is a more elegant solution out there. I'm looking for tips, tricks, and new functions which might make this formula more efficient and robust.
As in the above images, the numbering style I need to emulate is an X.X.X.X style where the first digit is shown and incremented for each major title, and subsequent digits are added according to the "step" in the column. The numbering style is fairly simple but the logic to implement it was not. Here is the formula placed in the cell next to "Toys":
It might be difficult to tease out from the above word salad, but effectively I've looked at IF column B contains something, check the first item immediately above in column B and extract the number. Then add 1. This is why the number next to "Title" is a zero.
For each step, it is checking if that cell contains something and then looks at if there was something that came prior or if it is the first in that stack. This proved quite the challenge and really is the bulk of the formula as it gets repeated three times over for each subsequent column.
If this was VBA I could set up a loop or some other tidier solution. My solution also has these current weaknesses (that I've found, there are probably more):
Thanks in advance!
I've been trying to create a numbering formula in one cell which can instantly itemise a schedule of items just by dragging and copying down said formula. However, it is quite complex (read janky) and I'm sure there is a more elegant solution out there. I'm looking for tips, tricks, and new functions which might make this formula more efficient and robust.
As in the above images, the numbering style I need to emulate is an X.X.X.X style where the first digit is shown and incremented for each major title, and subsequent digits are added according to the "step" in the column. The numbering style is fairly simple but the logic to implement it was not. Here is the formula placed in the cell next to "Toys":
Excel Formula:
=IF(B3<>"",OFFSET(INDEX($B$2:B2,MATCH(LOOKUP(2,1/($B$2:B2<>""),$B$2:B2),$B$2:B2,0),1),0,-1)+1,IF(C3<>"",IF(LEFT(A2,1)=LEFT(OFFSET(INDEX($C$2:C2,MATCH(LOOKUP(2,1/($C$2:C2<>""),$C$2:C2),$C$2:C2,0)),0,-2),1),CONCAT(LEFT(A2),".",MID(OFFSET(INDEX($C$2:C2,MATCH(LOOKUP(2,1/($C$2:C2<>""),$C$2:C2),$C$2:C2,0)),0,-2),3,1)+1,),CONCAT(LEFT(A2,1),".",IF(C2<>"",MID(A2,3,1)+1,1))),IF(D3<>"",IF(LEFT(A2,5)=LEFT(OFFSET(INDEX($D$2:D2,MATCH(LOOKUP(2,1/($D$2:D2<>""),$D$2:D2),$D$2:D2,0)),0,-3),5),CONCAT(LEFT(A2),".",MID(A2,3,1),".",MID(OFFSET(INDEX($D$2:D2,MATCH(LOOKUP(2,1/($D$2:D2<>""),$D$2:D2),$D$2:D2,0)),0,-3),5,1)+1),CONCAT(LEFT(A2,1),".",MID(A2,3,1),".",IF(D2<>"",MID(A2,5,1)+1,1))),IF(E3<>"",CONCAT(LEFT(A2,1),".",MID(A2,3,1),".",MID(A2,5,1),".",IF(E2<>"",MID(A2,7,1)+1,1)),1))))
It might be difficult to tease out from the above word salad, but effectively I've looked at IF column B contains something, check the first item immediately above in column B and extract the number. Then add 1. This is why the number next to "Title" is a zero.
For each step, it is checking if that cell contains something and then looks at if there was something that came prior or if it is the first in that stack. This proved quite the challenge and really is the bulk of the formula as it gets repeated three times over for each subsequent column.
If this was VBA I could set up a loop or some other tidier solution. My solution also has these current weaknesses (that I've found, there are probably more):
- If a step heading is repeated, the formula finds the step heading that is at the top, not the most recent heading. This ruins the numbering.
- If a column is skipped (i.e. something in Step 1 and then the next row contains something in Step 3) the whole formula dissolves. Not great.
- If a row is blank, everything breaks. Also not great.
Thanks in advance!