Desperaotto
New Member
- Joined
- Apr 25, 2017
- Messages
- 4
Hello,
I am a first time poster but have used a lot of these threads in the past in increasing my excel skills. I am using Excel 2016 on Windows 7 Pro.
My question is how can I get a VBA macro to activate upon either hitting enter or leaving the cell?
To provide background in what I am trying to accomplish I have a VBA code that is designed to perform a vlookup after something is picked from a drop down list. I am trying to populate both a value that shows a job code and job title in the pick list but only populates a job code once selected since there are other formulas in the spreadsheet which auto-populate based on the job code. Since this report is used in other areas with a define column length, I don't want to have a "help" column to perform this action. I was able to write a VBA macro that accomplishes this action but the VBA only works after I leave the cell than re-select it. The code is below. Is there anyway I can update the VBA to run either when enter is hit or another cell is selected? Thanks for your help.
I am a first time poster but have used a lot of these threads in the past in increasing my excel skills. I am using Excel 2016 on Windows 7 Pro.
My question is how can I get a VBA macro to activate upon either hitting enter or leaving the cell?
To provide background in what I am trying to accomplish I have a VBA code that is designed to perform a vlookup after something is picked from a drop down list. I am trying to populate both a value that shows a job code and job title in the pick list but only populates a job code once selected since there are other formulas in the spreadsheet which auto-populate based on the job code. Since this report is used in other areas with a define column length, I don't want to have a "help" column to perform this action. I was able to write a VBA macro that accomplishes this action but the VBA only works after I leave the cell than re-select it. The code is below. Is there anyway I can update the VBA to run either when enter is hit or another cell is selected? Thanks for your help.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
selectedVal = Target.Value
If Target.Column = 7 Then
selectednum = Application.VLookup(selectedVal, Worksheets("Look up Table").Range("picklist"), 2, False)
If Not IsError(selectednum) Then
Target.Value = selectednum
End If
End If
End Sub
Last edited by a moderator: