View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
cht13er cht13er is offline
external usenet poster
 
Posts: 141
Default Matching IDs with Names (VB)

On Apr 7, 11:16*am, "
wrote:
Lets say I have a workbook with ID numbers in it. *I have a macro
doing a lot of work on this workbook and one of the things I want it
to do is to convert the ID numbers into names. *I haven't done this
with VB before and was wondering what the best/easiest way to do this
would be? *If I wasn't doing it with a macro, I would just have a
vlookup, but this isn't an option for my case. *I have looked into
arrays, but this seems like it would be hard to populate and search
thru. *My idea was to create two arrays:

IDs = Array (1111,2222,3333,4444)
Names = Array("Bob","John","Henry","Sue")

The real data would contain about 20 elements. *I would rarely if ever
need to add or change IDs/Names. *Then as I find the ID value in the
cell, it would look thru the ID array, find the index of the value,
the pull up the corresponding index in the names array. *This seems
cumbersome and I am sure there has to be a better way to do this.

Thanks,
* Andrew V. Romero


With only twenty items, that wouldn't be cumbersome at all, and will
work OK.

outvalue = "" 'clear previous value
For iCounter = 1 to 20
if Invalue = ID(iCounter) then
OutValue = Names(icounter)
End if
next icounter

if outvalue = "" then
call msgbox( .... ) 'no result
else
'whatever you need to do
end if



HTH

Chris