Dropdown List to return another value in a table

Groovy Chick

Board Regular
Joined
Oct 10, 2017
Messages
75
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have an Excel worksheet in column F where I need to refer to numbers instead of putting in text. To explain I have four categories - employee, agency worker, contractor and visitor. Instead of returning the name I want to return 1, 2, 3 or 4 respectively. I have created a dropdown in the cell with the text description. I have a table on another sheet called WorkerCat which is two columns with the text and corresponding number. I've created the following code but it's not working. It finds the text from the dropdown but not the corresponding number in the table. Can anyone tell me what I am doing wrong? Many thanks in advance.

Private Sub Worksheet_Change(ByVal Target As Range)

selectedNa = Target.Value
If Target.Column = 6 Then
selectedNum = Application.VLookup(selectedNa, Sheets("WorkerCat").ListObjects("WorkerCat").DataBodyRange.Select, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub
 
Hi Dave, tried again and still not working. I've put the code on the active sheet and saved it as an xlsb and enabled content. I assume that's correct?
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I've put the code on the active sheet and saved it as an xlsb and enabled content. I assume that's correct?
normal file format is xlsm but should ok

check the following

- macros are enabled
- code is in the activesheet code page
- you have set data validation to allow other entries by unchecking "show error alert"
- the data validation text list matches text in the 1st column of your table

if this is all correct, then should work.

Dave
 
Upvote 0
If events are disabled I think that xl needs to be closed, rather than just the workbook. Either that or re-enabled by code.
 
Upvote 0
If events are disabled I think that xl needs to be closed, rather than just the workbook. Either that or re-enabled by code.

I appreciate that & may have directed OP incorrectly - hopefully that all it is.

Dave
 
Upvote 0
Tried again this morning with shutting Excel down completely. That worked! Awesome, thank you so much to you both for your help. Much appreciated.
 
Upvote 0
Tried again this morning with shutting Excel down completely. That worked! Awesome, thank you so much to you both for your help. Much appreciated.

I said I missed something and as @Fluff reminded me, should have said to close the excel application & not just the workbook to reset EnableEvents.

Glad we were able to help & issue resolved - appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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