Vlookup in VBA?

privxls

Board Regular
Joined
Nov 22, 2016
Messages
55
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone,

First, I'd like to thank everyone who previously helped me and now I'm back to ask for more of the expert's suggestions and help.

I am currently working on a mini project where I aim to use Buttons, Textboxes in VBA to do a 'vlookup', that if... it's possible.

So here's how it looks like:
wKxtlTz.png



Here's where the reference would be from:
emhbUe2.png



Is there a way for me to do it?

Thank you everyone!
-Privxls
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi Privxls,

I do not understand your question fully, but I will answer you based on what I understand.

A VLookup works as follows: Look at the sorted list in location, and then find within the first column the Look-Up Value and from that same row where that Look-Up Value is located give me the value in a certain Column.

Since you have the buttons named, you can get the name of the button, or the caption of the button, pressed, and then look for that value in your Reference area. and return Column 2.

I guess that might be what you need to do, if you need a code example, I am not at my computer right this minute, but I will be happy to send you a sample later.
 
Upvote 0
I guess I did not make it clear. I just re-read the thread and it did not make much sense, sorry.

But yes, that's how I'd want it to go Phils. I tried doing "Application.WorksheetFunction.Vlookup" -- yet I encountered compile error.

I'd really appreciate it if you can share it with me.

Thank you PhilS2520

Kind regards,
Privxls.
 
Upvote 0
Privxls

What exactly should the buttons on the userform do?
 
Upvote 0
Hi Norie,

The buttons should show the corresponding text in the reference area. For an example, the user clicks on button 'Smith 1' it will then show in Text Box 1,2 and 3 the corresponding values in it, same goes for the rest of the buttons. It's like doing a vlookup.
Could there be a better way of doing it than what I currently think of?

Kind regards,
Privxls.

(edit - punctuation)
 
Last edited:
Upvote 0
Privxls

VLOOKUP would only return the first instance where there was a match, e.g. for 'Smith 2' it would return 'On the docks'.

If you wanted to return all the instances that matched you would need to take another approach.
 
Upvote 0
Ohh... do you have any suggestions Norie?

Kind regards,
Privxls.
 
Upvote 0
You can do that quite easily using variant arrays instead of vlookup, I never use vlookup in VBa because simple coding using variant arrays runs faster and is easier to debug and much more flexible as in this case where you want to return every match. ( to do this just leave out the EXIT for)

Have a look at this thread for a VBA altenative to Vlookup:
https://www.mrexcel.com/forum/excel-questions/1043185-vlookup-vba-alternative.html
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,611
Members
452,660
Latest member
Zatman

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