Search Function help

Ryan_H

New Member
Joined
Apr 22, 2011
Messages
2
Hello everyone. I am attempting to take a stab at creating a function to do a lookup in one sheet of data from another sheet. I have attempted to do this myself but have failed miserably, so I would appreciate any help you can provide.

Basically what the first sheet has is a cell that contains a 1 or a 2 which will tell me which column to use in the second sheet. The first sheet also contains another cell with a value in it. When the user inputs a value here I want to go to the second sheet and find the last row that is greater than the value they entered (they are already in ascending order). Based on whether the user has entered a 1 (for column 1) or a 2 (for column 2) in the first cell the appropriate value from that row will be returned to populate another cell on the first sheet.

Please see the following example as to what the second sheet would look like followed by some sample values that could be passed in.


value ... col1 ... col2
10 ........ a ........ b
20 ........ c ........ d
30 ........ e ........ f
40 ........ g ........ h
50 ........ i ......... j
60 ........ k ........ l


value = 32
column = 2

returns: f

If you could please provide some direction as to how to do such a thing I would really appreciate it.

Thanks,
Ryan
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello everyone. I am attempting to take a stab at creating a function to do a lookup in one sheet of data from another sheet. I have attempted to do this myself but have failed miserably, so I would appreciate any help you can provide.

Basically what the first sheet has is a cell that contains a 1 or a 2 which will tell me which column to use in the second sheet. The first sheet also contains another cell with a value in it. When the user inputs a value here I want to go to the second sheet and find the last row that is greater than the value they entered (they are already in ascending order). Based on whether the user has entered a 1 (for column 1) or a 2 (for column 2) in the first cell the appropriate value from that row will be returned to populate another cell on the first sheet.

Please see the following example as to what the second sheet would look like followed by some sample values that could be passed in.


value ... col1 ... col2
10 ........ a ........ b
20 ........ c ........ d
30 ........ e ........ f
40 ........ g ........ h
50 ........ i ......... j
60 ........ k ........ l


value = 32
column = 2

returns: f

If you could please provide some direction as to how to do such a thing I would really appreciate it.

Thanks,
Ryan
Try this...

Table on Sheet1 in the range A2:C7

On some other sheet:
  • A2 = some number like 32
  • B2 = column number like 2
Then:

=VLOOKUP(A2,Sheet1!A2:C7,B2+1)
 
Upvote 0
Sheet1

A2: 32

B2: 2

In C2 enter:

=INDEX(Sheet2!$B$2:$C$6,MATCH(A2,Sheet2!$A$2:$A$6,0),$B2)

where A2:C6 on Sheet2 houses the table you provided.
 
Upvote 0
Thank you both for your quick responses. I tried your solution, Biff, and it worked wonderfully. I appreciate the elegant function.

Regards,
Ryan
 
Upvote 0
Thank you both for your quick responses. I tried your solution, Biff, and it worked wonderfully. I appreciate the elegant function.

Regards,
Ryan

I see I overlooked the values in ascendin order...

Just change 0 in MATCH to 1.
 
Upvote 0

Forum statistics

Threads
1,215,390
Messages
6,124,667
Members
449,178
Latest member
Emilou

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