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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,179
Messages
6,129,334
Members
449,503
Latest member
glennfandango

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