Associate Name to Number

rjwebgraphix

Well-known Member
Joined
May 25, 2010
Messages
590
Code isn't really need, I can figure that out, but looking for alternate ideas that might be better than what I'm thinking...

I need to associate a number to name. I was thinking about just using a simple array with a single string in each array element separated by a space. Left of the space is the Name, Right of the space is the number.

Most of the time it would only be a single association, but I need to account for multiple Names to their respective Number. A simple array in the fashion mentioned sounds the easiest, but I tend to forget about other common practices since I'm mostly all self-taught and just use it for side projects.

What do you think?

RJ
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Why not create a lookup table, of each name/number combination, and use VLOOKUP?
 
Last edited:
Upvote 0
Other possibilities:
Two identically sized arrays, one holds the names (ArrNames), the other the numbers (ArrayNums) such that the number corresponding to ArrayName(i) is ArrayNum(i).

A two-column lookup table in a worksheet with Names and Numbers (say A2:B100 for example) and use a Variant (say V) as a 2-D array like this:
V=Range("A2:B100").Value. Then V(i,1) is a name with associated number V(i,2) and so on ....
 
Upvote 0
Other possibilities:
Two identically sized arrays, one holds the names (ArrNames), the other the numbers (ArrayNums) such that the number corresponding to ArrayName(i) is ArrayNum(i).

This could work better. The array count would also be the same if building them at the same time. Perfect. Thanks.

Edit: Maybe not, because I'll need to sort the array alphabetically by name, so they appear in the correct order when displayed and there's no way to keep that association as two separate arrays. :/ I guess a single array is the best way without going to a multi-dimensional array.

Joe4 said:
Why not create a lookup table, of each name/number combination, and use VLOOKUP?


For this purpose, code is better. No need to add data that is only used in code.
 
Last edited:
Upvote 0
Replied before thinking it through and added an Edit. :/ #crazyface :)


In that case I'd be inclined to create a table in some out of the way place on a worksheet and use the 2-D variant array I suggested. Makes it very easy to add/remove names and to sort the names alphabetically.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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