Groovy Chick
Board Regular
- Joined
- Oct 10, 2017
- Messages
- 75
- Office Version
- 2016
- Platform
- 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