Comparing a string with all values in a range

ajuece19

New Member
Joined
Jan 19, 2016
Messages
1
I have a sheet with two columns "type", "code" with some values. The "type" column contains unique values. But the "code" contains values which categorize the values in "type" column.

typecode
1a
2c
3f
4c
5a
6b
7a
8e
9g
10d

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

types 1,5,7 are mapped to the code "a" ... it goes like this.

Now i have a string stored in a variable in my code which will return a "type". Now i need to look up this table and see the "code" of the corresponding "type" returned and store it in another variable.

Not sure i have explained it correctly. I am very new to VBA coding. Please help me out.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You need to loop through your table looking at the type column, comparing values to the one you are looking for. Use the value of the loop, to pull the adjacent value from the column code once the loop has matched. For example, For x = 1 to 10 looking = cells(x+1),1) if looking = "the value you are looking for" then thecode = cells(x+1,2) next note: I have assumed that table is sat at the top left of a sheet, so hence row 1 is the headers, so that is why I added 1 to the loop value x to start looking at row 2.
 
Upvote 0

Forum statistics

Threads
1,216,778
Messages
6,132,665
Members
449,745
Latest member
victoriar

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