D
Dana M
Note - current code is at the bottom of this question. I'm not sure, but
think this is called a worksheet event?
In columns C and D of several sheets in a template, I have drop down boxes
for selecting Type and Owner. If the user selects a Type Name, a Type
Abbreviation is returned (from a hidden "Code" sheet), ie; select Apple,
template shows AP, select Jack Web, template returns JW. The Type and Owner
drop downs are adjacent, in Columns C and D, but are not in every row
because of subtotals and blank rows.
My problem - users sometimes key in "AP" instead of selecting
"Apple", or copy/paste "AP" from another row. These actions are causing
errors.
Is there a way to either revise the following code so that copy/paste or
keying in an "AP" gives the same result
as selecting Apple from the Drop Down? Or alternately, not allow the user to
do anything but select - with a message if they attempt - that they need to
select from the drop down options? Here is my
current code - on right click of the worksheet tab/show code /
.........................
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then GoTo exitHandler
If Target.Column = 3 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True
If Target.Cells.Count > 1 Then GoTo exitHandler
If Target.Column = 4 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
End Sub
think this is called a worksheet event?
In columns C and D of several sheets in a template, I have drop down boxes
for selecting Type and Owner. If the user selects a Type Name, a Type
Abbreviation is returned (from a hidden "Code" sheet), ie; select Apple,
template shows AP, select Jack Web, template returns JW. The Type and Owner
drop downs are adjacent, in Columns C and D, but are not in every row
because of subtotals and blank rows.
My problem - users sometimes key in "AP" instead of selecting
"Apple", or copy/paste "AP" from another row. These actions are causing
errors.
Is there a way to either revise the following code so that copy/paste or
keying in an "AP" gives the same result
as selecting Apple from the Drop Down? Or alternately, not allow the user to
do anything but select - with a message if they attempt - that they need to
select from the drop down options? Here is my
current code - on right click of the worksheet tab/show code /
.........................
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then GoTo exitHandler
If Target.Column = 3 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True
If Target.Cells.Count > 1 Then GoTo exitHandler
If Target.Column = 4 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
End Sub