Replace value from validation list with a number using VBA in Microsoft Excel

Question:

The selection from a validity list in column D shall be replaced by a number. Works only with XL9 and higher.

Answer:

Place the code below into the This Workbook module.

Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Column <> 4 Then Exit Sub
   Application.EnableEvents = False
   Target.Value = WorksheetFunction.VLookup(Target.Value, Range("A1:B12"), 2, 0)
   Application.EnableEvents = True
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.