Please help with formula

Andries

Board Regular
Joined
Feb 3, 2011
Messages
127
Hi

Please help me with a formula. I have two tables...the lookup data is in the first table (colums A,B and C...this data is obviously only a small part of the actual data)

Excel Workbook
ABC
2BLOCK/ROW/SEATSUBJECT CODEO/B
3w2-81-1MNP20YT*
4w2-81-2MNP20YT*
5w2-81-3PTL311T*
6w2-81-4PTL311T*
7w2-81-5AMF40AT*
8w2-81-6BMN23BD*
9w2-81-7DLM501TO/B
10w2-81-8DLM501TO/B
11w2-81-9DLM501TO/B
12w2-81-10DLM501TO/B
13w2-82-1DLM501TO/B
14w2-82-2DLM501TO/B
15w2-82-3DLM501TO/B
16w2-82-4DLM501TO/B
17w2-82-5DLM501TO/B
18w2-82-6DLM501TO/B
19w2-82-7DLM501TO/B
20w2-82-8DLM501TO/B
21w2-82-9DLM501TO/B
22w2-82-10DLM501TO/B
23w2-83-1DLM501TO/B
24w2-83-2DLM501TO/B
25w2-83-3DLM501TO/B
26w2-83-4DLM501TO/B
27w2-83-5DLM501TO/B
28w2-83-6DLM501TO/B
29w2-83-7DLM501TO/B
30w2-83-8DLM501TO/B
31w2-83-9DLM501TO/B
32w2-83-10DLM501TO/B
data2



The second table must have the lookup formula to return the subject code in Column I and K and M. The problem that I have is if the subject code has an "O/B" next to it in Column C it must start in a new block

Excel Workbook
HIJKLM
2BLOCK/ROW/SEATSUBJECT CODEBLOCK/ROW/SEATSUBJECT CODEBLOCK/ROW/SEATSUBJECT CODE
3w2-81-1*w2-82-1*w2-83-1*
4w2-81-2*w2-82-2*w2-83-2*
5w2-81-3*w2-82-3*w2-83-3*
6w2-81-4*w2-82-4*w2-83-4*
7w2-81-5*w2-82-5*w2-83-5*
8w2-81-6*w2-82-6*w2-83-6*
9w2-81-7*w2-82-7*w2-83-7*
10w2-81-8*w2-82-8*w2-83-8*
11w2-81-9*w2-82-9*w2-83-9*
12w2-81-10*w2-82-10*w2-83-10*
data2



Please look at the last table...it must be populated like this


Excel Workbook
HIJKLM
14BLOCK/ROW/SEATSUBJECT CODEBLOCK/ROW/SEATSUBJECT CODEBLOCK/ROW/SEATSUBJECT CODE
15w2-81-1MNP20YTw2-82-1DLM501T - O/Bw2-83-1DLM501T - O/B
16w2-81-2MNP20YTw2-82-2DLM501T - O/Bw2-83-2DLM501T - O/B
17w2-81-3PTL311Tw2-82-3DLM501T - O/Bw2-83-3DLM501T - O/B
18w2-81-4PTL311Tw2-82-4DLM501T - O/Bw2-83-4DLM501T - O/B
19w2-81-5AMF40ATw2-82-5DLM501T - O/Bw2-83-5DLM501T - O/B
20w2-81-6BMN23BDw2-82-6DLM501T - O/Bw2-83-6DLM501T - O/B
21w2-81-7*w2-82-7DLM501T - O/Bw2-83-7DLM501T - O/B
22w2-81-8*w2-82-8DLM501T - O/Bw2-83-8DLM501T - O/B
23w2-81-9*w2-82-9DLM501T - O/Bw2-83-9DLM501T - O/B
24w2-81-10*w2-82-10DLM501T - O/Bw2-83-10DLM501T - O/B
data2


It is currently looking like this which is not correct and it must look like the above table

Excel Workbook
HIJKLM
14BLOCK/ROW/SEATSUBJECT CODEBLOCK/ROW/SEATSUBJECT CODEBLOCK/ROW/SEATSUBJECT CODE
15w2-81-1MNP20YTw2-82-1DLM501T - O/Bw2-83-1DLM501T - O/B
16w2-81-2MNP20YTw2-82-2DLM501T - O/Bw2-83-2DLM501T - O/B
17w2-81-3PTL311Tw2-82-3DLM501T - O/Bw2-83-3DLM501T - O/B
18w2-81-4PTL311Tw2-82-4DLM501T - O/Bw2-83-4DLM501T - O/B
19w2-81-5AMF40ATw2-82-5DLM501T - O/Bw2-83-5DLM501T - O/B
20w2-81-6BMN23BDw2-82-6DLM501T - O/Bw2-83-6DLM501T - O/B
21w2-81-7DLM501T - O/Bw2-82-7DLM501T - O/Bw2-83-7DLM501T - O/B
22w2-81-8DLM501T - O/Bw2-82-8DLM501T - O/Bw2-83-8DLM501T - O/B
23w2-81-9DLM501T - O/Bw2-82-9DLM501T - O/Bw2-83-9DLM501T - O/B
24w2-81-10DLM501T - O/Bw2-82-10DLM501T - O/Bw2-83-10DLM501T - O/B
data2


Thank you in advance
Dries
 
Hi Peter

It must look like TABLE 2
Thank you. :)

This suggestion uses a helper cell to keep the column F formula a bit shorter. I have used cell I2 for this. Formula in F2 is copied down. You may have to adjust the range in the F2 formula before copying as I'm not sure whether your data goes to row 200 or beyond.

Excel Workbook
ABCDEFGHI
1TABLE 1TABLE 2
2w2-81-1Aw2-81-1A6
3w2-81-2Bw2-81-2B
4w2-81-3Cw2-81-3C
5w2-81-4Dw2-81-4D
6w2-81-5Ew2-81-5E
7w2-81-6Fw2-81-6F
8w2-81-7GO/Bw2-81-7
9w2-81-8HO/Bw2-81-8
10w2-81-9IO/Bw2-81-9
11w2-81-10JO/Bw2-81-10
12w2-82-1KO/Bw2-82-1G
13w2-82-2LO/Bw2-82-2H
14w2-82-3MO/Bw2-82-3I
15w2-82-4NO/Bw2-82-4J
16w2-82-5OO/Bw2-82-5K
17w2-82-6PO/Bw2-82-6L
18w2-82-7QO/Bw2-82-7M
19w2-82-8RO/Bw2-82-8N
20w2-82-9SO/Bw2-82-9O
21w2-82-10TO/Bw2-82-10P
22w2-83-1Uw2-83-1Q
23w2-83-2Vw2-83-2R
24w2-83-3Ww2-83-3S
25w2-83-4w2-83-4T
26w2-83-5w2-83-5U
27w2-83-6w2-83-6V
28w2-83-7w2-83-7W
data2



If you don't want to use the helper cell then the F2 formula would need to be:

=IF(ROWS(F$2:F2)<=COUNTBLANK(C$2:C$11),B2,IF(ROWS(F$2:F2)<=10,"",INDEX($B$2:$B$200,ROWS(F$2:F2)-10+COUNTBLANK(C$2:C$11))))
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi Peter

It is perfect and working for real this time. Thanks for putting up with me.

Regards,

Dries
 
Upvote 0
It is perfect and working for real this time. Thanks for putting up with me.
No problem, it just took a long time to show what you wanted rather that what you didn't want. :)

Just one further thing, if you were to use another helper column like column H below, the formulas would be considerably simpler and require less calculation resources. The helper column(s) could be hidden after they have been filled in if you don't like their visual impact.

Column H is just filled with 1, 2, 3 etc from row 2 down. The new formula for F2 is shown below my screen shot.

Excel Workbook
ABCDEFGHI
1TABLE 1TABLE 2
2w2-81-1Aw2-81-1A16
3w2-81-2Bw2-81-2B2
4w2-81-3Cw2-81-3C3
5w2-81-4Dw2-81-4D4
6w2-81-5Ew2-81-5E5
7w2-81-6Fw2-81-6F6
8w2-81-7GO/Bw2-81-77
9w2-81-8HO/Bw2-81-88
10w2-81-9IO/Bw2-81-99
11w2-81-10JO/Bw2-81-1010
12w2-82-1KO/Bw2-82-1G11
13w2-82-2LO/Bw2-82-2H12
14w2-82-3MO/Bw2-82-3I13
15w2-82-4NO/Bw2-82-4J14
16w2-82-5OO/Bw2-82-5K15
17w2-82-6PO/Bw2-82-6L16
data2
 
Upvote 0
Hi Peter

What if the column C's value is variable...meaning that "O/B" will not always start in Cell C8
but it can start anywhere else in column C?
 
Upvote 0
Hi Peter

What if the column C's value is variable...meaning that "O/B" will not always start in Cell C8
but it can start anywhere else in column C?
I don't know what the consequence of that is. What results would you expect if it started, for example, in

a) C3?

b) C14?
 
Upvote 0
Hi Peter

If "O/B" start in C3 then the formula works fine by placing/starting it in the next set but when it starts in C14 it should then place it in the next set that follows (F18)

Currently it is doing this:


Excel Workbook
ABCDEF
1TABLE 1TABLE 2
2w2-81-1Aw2-81-1A
3w2-81-2Bw2-81-2B
4w2-81-3Cw2-81-3C
5w2-81-4Dw2-81-4D
6w2-81-5Ew2-81-5E
7w2-81-6Fw2-81-6F
8w2-81-7Gw2-81-7G
9w2-81-8Hw2-81-8H
10w2-81-9Iw2-81-9I
11w2-81-10Jw2-81-10J
12w2-82-1Kw2-82-1K
13w2-82-2Lw2-82-2L
14w2-82-3Mw2-82-3M
15w2-82-4NO/Bw2-82-4Q
16w2-82-5OO/Bw2-82-5R
17w2-82-6PO/Bw2-82-6S
18w2-83-1QO/Bw2-83-1T
19w2-83-2RO/Bw2-83-2U
20w2-83-3SO/Bw2-83-3V
21w2-83-4TO/Bw2-83-4W
22w2-83-5UO/Bw2-83-5X
23w2-83-6VO/Bw2-83-6Y
24w2-83-7WO/Bw2-83-7Z
25w2-83-8XO/Bw2-83-80
26w2-83-9YO/Bw2-83-90
27w2-83-10ZO/Bw2-83-100
data2
 
Upvote 0
It appears from your last screen shot that the 'sets' are no longer uniform in size and are only identified by colour. If that is the case I don't see how a formula could do what you want, at least without helper columns that would need manual entry to identify the start of each 'set'. Please confirm whether the 'sets' are uniform size or not.

(Once again you appear to have shown the result you don't want, not the result you do want :( )

Also, the formula you have shown in your last post is not the formula I provided in post #21. That formula would have produced this result (which I know is still not what you want)

Excel Workbook
ABCDEF
2w2-81-1Aw2-81-1A
3w2-81-2Bw2-81-2B
4w2-81-3Cw2-81-3C
5w2-81-4Dw2-81-4D
6w2-81-5Ew2-81-5E
7w2-81-6Fw2-81-6F
8w2-81-7Gw2-81-7G
9w2-81-8Hw2-81-8H
10w2-81-9Iw2-81-9I
11w2-81-10Jw2-81-10J
12w2-82-1Kw2-82-1K
13w2-82-2Lw2-82-2L
14w2-82-3Mw2-82-3M
15w2-82-4NO/Bw2-82-4N
16w2-82-5OO/Bw2-82-5O
17w2-82-6PO/Bw2-82-6P
18w2-83-1QO/Bw2-83-1Q
19w2-83-2RO/Bw2-83-2R
20w2-83-3SO/Bw2-83-3S
21w2-83-4TO/Bw2-83-4T
22w2-83-5UO/Bw2-83-5U
23w2-83-6VO/Bw2-83-6V
24w2-83-7WO/Bw2-83-7W
25w2-83-8XO/Bw2-83-8X
26w2-83-9YO/Bw2-83-9Y
27w2-83-10ZO/Bw2-83-10Z
data2 32 (2)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

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