A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Change ActiveSheet to Worksheets("Material")
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have the following code to enter a value based on a drop down. It works well if the table is on the same sheet; however, I need for this to work with the data in a different sheet named "Material"
[code]
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 4 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("Material_List"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub
[code]
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Change ActiveSheet to Worksheets("Material")
Oh the first one is suppose to be column 4 the other should be 6. I am getting an error in the end sub
You have 2 sections of code that both apply to the same column 4 (column D) buy that look up a value in a different table.
How should that work?
Another Question . . . If I want multiple change events on same worksheet? I tried this, but does not work:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 4 Then
selectedNum = Application.VLookup(selectedNa, Worksheets("Materials").Range("Material\_List"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
If Target.Column = 4 Then
selectedNum = Application.VLookup(selectedNa, Worksheets("Time").Range("Time\_List"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
Exit Sub
End Sub
I knew it was a simple fix. Thank you for the quick reply!