This is what I need to do ... I have a column where I would like to either hit F and have 'FHB' appear in the cell or hit D and have DFGY appear. What is the code that I should use to have this happen?
Thanks.
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
You would need to use a Worksheet_Change event handler. The following example assumes your column to evaluate is column A (column 1).
If your column is not A, the change the '1' to a number representing your column, i.e. A = 1, Z = 26, etc.
Then, copy the event handler below, modified as needed, to the clipboard (highlight the entire code, right click inside the code, and 'Copy'):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
If UCase(Target.Value) = "F" Then
Target.Value = "FHB"
ElseIf UCase(Target.Value) = "D" Then
Target.Value = "DFGY"
End If
End If
End Sub
Select the worksheet containing the column you wish to monitor and right click the sheet tab at the bottom.
Select 'View Code'.
Paste the event handler into the white editing area to the right (right click inside the area and 'Paste').
Close the VBE (red button w/white 'x' - top right.
Enter data in your designated column and TAB or ENTER and it will be returned as desired.
Note: the event handler is not case sensitive, so you can enter either 'f' or 'F', and it will return 'FHB', etc.