Reverse Search for Value

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
608
Office Version
  1. 365
Platform
  1. Windows
I thought this was going to be simple but I cannot figure out what direction to take. In column B, I am looking for a formula that will do a search backwards up column C if Column A as the word ID in it.
Column B has the results I am looking for. The number of rows and IDs appear randomly, they are never the same amount between each other. The values always start with H27-.

Any help is appreciated

Book1
ABC
1IDsResultsValue
2H27-12
3
4
5
6IDH27-12
7IDH27-13
8IDH27-14
9IDH27-15
10
11
12
13
14
15H27-18
16IDH27-18
17IDH27-18
18
19
20
21H27-1324
22IDH27-1324
Sheet6
 

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.
Are the results meant to increase as they do in B6:B9, or should they be the same as in B16:B17?

Perhaps this as long as the empty cells are actually empty and not blank?
Book2
ABC
1IDsResultsValue
2 H27-12
3 
4 
5 
6IDH27-12
7IDH27-12
8IDH27-12
9IDH27-12
10 
11 
12 
13 
14 
15 H27-18
16IDH27-18
17IDH27-18
18 
19 
20 
21 H27-1324
22IDH27-1324
Sheet2
Cell Formulas
RangeFormula
B2:B22B2=IF(A2="ID",LOOKUP("zzz",C$1:C1),"")
 
Upvote 0
Hello,
Thank you for your reply. My mistake on range B6:B9. You are correct in your results. What does the Lookup("ZZZ") do? I have never used it.
 
Upvote 0
It's an approximate lookup, so it finds the last entry in the list that has a value less than or equal to "zzz".
Note that it only works with text (alphanumeric strings are still classed as text for formula purposes), if you were looking for numbers then you would need to use a number like 1e+100 instead (that's 1 followed by 100 zero's in scientific notiation).

Formula blanks will cause problems with this method as "" is evaluated as text so the formula will see that and not the string above it, a workaround for that would require a more complex and less efficient formula.
 
Upvote 0
I found that the format changes from time to time in the report. Column A might have an ID on the same line as the Value. I solved that by adding another condition and using the Search function.

I have a new issue which sounds like I have to use the 1e+100 that you were talking about. Occasionally, there is text in column C. Out of the 6,000 rows, there were only 4 occurrences. If there is a way to get around that, great. If not, it might not be the end of the world.

Book1
ABC
1H27-12
2 
3 
4 
5IDH27-12
6IDH27-12
7IDoiloil
8IDoil
9 
10 Car
11 
12 
13 
14IDH27-18H27-18
15IDH27-18
16IDH27-18
17 train
18 
19 
20 H27-1324
21IDH27-1324
Sheet6 (2)
Cell Formulas
RangeFormula
B2:B21B2=IF(AND(A2="ID",ISNUMBER(SEARCH("h27",C2))),C2,IF(A2="ID",LOOKUP("zzz",C$1:C2),""))
 
Upvote 0
Try this one in B2 and fill down

=IF(A2="ID",LOOKUP(2,1/(LEFT(C$2:C2,4)="H27-"),C$2:C2),"")
 
Upvote 0
That might be cos of the missing headers, the formula assumed data starting in row 2 as in the first example. Without headers it needs to be adjusted back with the first formula in B1 instead of B2

=IF(A1="ID",LOOKUP(2,1/(LEFT(C1:C$1,4)="H27-"),C1:C$1),"")
 
Upvote 0
Would you be opposed to an additional column?

In D1 you place =C1
In D2 you place =if(len($C2)>0,$C2,$D1)
In B1 you place =if(len($A1)>0,$D1,””)

Drag the formulas in B1 and D2 down to the end of the data range.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

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