Dropdown list and Vlookup simplification

jmcconnell

New Member
Joined
Feb 2, 2019
Messages
35
Hi,

I've got a drop down list (SiteList) and when I select an option for that list it looks up details in a spreadsheet called AMSM and fills in a text box(SMName) on the same sheet as the drop down list. There is about 30 options in the drop down list. There is a sample of 2 below:


Private Sub SiteList_Change()
Dim ws As Worksheet
Dim SManager As String
Set ws = Sheets("AMSM")

If SiteList = "Kelburn" Then
SManager = Application.VLookup("Kelburn", ws.Range("A1:c112"), 3)
SMName = SManager
ElseIf SiteList = "Garreg Lwyd" Then
SManager = Application.VLookup("Garreg Lwyd", ws.Range("A1:c112"), 3)
SMName = SManager
End IF

Rather than having if statements as above for all 30 options, is there a way of simplifying this - Perhaps with a loop?

Thank you for your help!!!
Kind regards,
James.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
How are you populating the Combobox?
 
Upvote 0
But how is it populated? By code, by listfillrange, or some other method?
Also is it an ActiveX or Form Control combo?
 
Upvote 0
Just realised what you meant by
Not the AMSM sheet though.
Which makes things a bit more awkward. Could you use col A on the AMSM for the listfillrange?
If not will the values in the listfillrange, always be in the sme order as they are in col A of AMSM?
 
Upvote 0
Ok, in that case you can use
VBA Code:
Private Sub SiteList_Click()

   SMName = Sheets("AMSM").Range("C" & SiteList.ListIndex + 1)
End Sub
This assumes that the listfillrange starts in A1, if it starts in A2 just change the +1 to +2
 
Upvote 0

Forum statistics

Threads
1,215,396
Messages
6,124,685
Members
449,179
Latest member
kfhw720

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