Hi,
I have a workbook that has 5 worksheets. Each sheet represents the days of the week. The problem is the code works in my workbook but not on others. It only populates the project name not the project number. The result wanted is for the user to select from the project name form the list on charge nums sheet and populate the project number at the same time for each day of the week. Excel fills in project name and project number in two different columns. The cells are lock to keep the user from entering data. The versions of excel are the same. Help if you can. Thanks
Each has the following code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim wsChargeNums As Worksheet
Dim ProjectListRow As Long
Dim ProjectNoRow As Long
On Error GoTo errHandler
Set wsChargeNums = Worksheets("Charge Nums")
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
Select Case Target.Column
Case 2
With Target
If .Value = "" Then
.Offset(0, 1).Value = ""
Else
ProjectListRow = Application.Match(.Value, wsChargeNums.Range("ProjectList"), 0)
.Offset(0, 1).Value = wsChargeNums.Range("ProjectNo")(ProjectNoRow).Value
End If
End With
Case 3
With Target
If .Value = "" Then
.Offset(0, -1).Value = ""
Else
ProjectListRow = Application.Match(.Value, wsChargeNums.Range("ProjectList"), 0)
.Offset(0, -1).Value = wsChargeNums.Range("ProjectNo")(ProjectListRow).Value
End If
End With
Case Else
'do nothing
End Select
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
GoTo exitHandler
End Sub
I have a workbook that has 5 worksheets. Each sheet represents the days of the week. The problem is the code works in my workbook but not on others. It only populates the project name not the project number. The result wanted is for the user to select from the project name form the list on charge nums sheet and populate the project number at the same time for each day of the week. Excel fills in project name and project number in two different columns. The cells are lock to keep the user from entering data. The versions of excel are the same. Help if you can. Thanks
Each has the following code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim wsChargeNums As Worksheet
Dim ProjectListRow As Long
Dim ProjectNoRow As Long
On Error GoTo errHandler
Set wsChargeNums = Worksheets("Charge Nums")
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
Select Case Target.Column
Case 2
With Target
If .Value = "" Then
.Offset(0, 1).Value = ""
Else
ProjectListRow = Application.Match(.Value, wsChargeNums.Range("ProjectList"), 0)
.Offset(0, 1).Value = wsChargeNums.Range("ProjectNo")(ProjectNoRow).Value
End If
End With
Case 3
With Target
If .Value = "" Then
.Offset(0, -1).Value = ""
Else
ProjectListRow = Application.Match(.Value, wsChargeNums.Range("ProjectList"), 0)
.Offset(0, -1).Value = wsChargeNums.Range("ProjectNo")(ProjectListRow).Value
End If
End With
Case Else
'do nothing
End Select
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
GoTo exitHandler
End Sub