vlookup in general

i m new in excel  macros and functions can i write a simple macro that can  let the user choose to use vlookup and hlookup in general
choose the excel file or other file and create the vlookup
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

byundtMechanical EngineerCommented:
Excel 2003 and 2007 have a Lookup wizard that helps people create VLOOKUP and HLOOKUP formulas. The wizard is an optional install. To get it, install the Lookup add-in.
asaidiAuthor Commented:
i did not get a real solution for my question..
the wizard no allow me to do what i want..
if there is an example from experts shows how to create vlookup manually ..

do you have an example file which shows what you are trying to do....

in general yes you can create a macro which can calculate the a value based on either vlookup or hlookup....

if a = 1 then ActiveCell.FormulaR1C1 = "=HLOOKUP(<cell>,<range>,<row>,FALSE)"
else ActiveCell.FormulaR1C1 = "=VLOOKUP(<cell>,<range>,<col>,FALSE)"

general concept of VLOOKUP/Hlookup =
 =vlookup(<value you want to lookup>,<range which contains the value you are looking up (this should always be the first column) and the value you want to return>,<column number of the value you want to return>, flase)
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

asaidiAuthor Commented:
hi wshark83
i have 2 sql table that i will export them as workbook then write my macros
please find attached 2 excel files
1 account and 2 is customer
will show all customer belongs to account
if i choose an account i can see the customers belongs to the account
please attach the file and upload it...cannot see the file...
asaidiAuthor Commented:
sorry about that
can you please provide me with the column headings for the two files...also brief explanation as to how do you envisage the macro to work...or what you want the user to be able to do....
asaidiAuthor Commented:
thank you for your time
for account (primary key)
col2=system_owner(linkded to another table ignore this please)
for customer
col1=auto_id(primary key)
col2=account_id(linked to account)==>auto_id of account
when i click on auto_id of account see all customers
you have missed a column in the customer file...

if you want to use the account file as a driver then isn't it easier to do a query i.e.:

sleect *
from account a
left join customer b
on a.auto_id = b.account_id


select *
from customer
where account_id in (select auto_id from account where auto_id = 1 )
asaidiAuthor Commented:
i have your sql in my script no problem it works  normally but the problem how i can make it work on excel vlookup..
if you have the code why do you need the excel vlookup...?

anways if you want VBA you would need to loop the code until it doesn't find any occurances...here's an example on loop vba code - look at the last one "To Search a List for a Specific Record"

asaidiAuthor Commented:
sorry about that the 2 excel i sent you only an example of what io want to do
in vlookup
i need to find for example a name when i type the code and the name i need to find him in another excel file..
is there any good example in excel about this issue
code:|________________|       name:dipslay
do you mean to say something like this (see attached file in account tab...new column called "Customer"...?
asaidiAuthor Commented:
exactly what i want
if you have multiple customer with the same account id then you would need to reverse it i.e. look up account for all customers for the vlookup to work...alternatively use the macro above to get the cell reference...as the vlookup will only get the first value...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asaidiAuthor Commented:
i will do it thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.