Drop Down Change Product Name to Code

Suasponte

New Member
Joined
Mar 5, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
using a fantastic tutorial by Debra Dalgleish i have this running sort of ..

but i need to have another column do the same action on a different workbook and it has me stumped. Any help would be appreciated.

Many thanks. and im sure it obvious .. but been decades for me

Option Explicit

Private Sub Worksheet_Change _
(ByVal Target As Range)
On Error GoTo errHandler

Dim wsCodes As Worksheet
Set wsCodes = Worksheets("Codes")

If Target.Cells.Count > 1 _
Then GoTo exitHandler

If Target.Column = 4 Then
If Target.Value = "" _
Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = wsCodes.Range("A1") _
.Offset(Application. _
WorksheetFunction _
.Match(Target.Value, _
wsCodes.Range("ProdList"), 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

Private Sub Worksheet_Change2 _
(ByVal Target As Range)
On Error GoTo errHandler

Dim wsCodes As Worksheet
Set wsCodes = Worksheets("Suppliers")

If Target.Cells.Count > 1 _
Then GoTo exitHandler

If Target.Column = 10 Then
If Target.Value = "" _
Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = wsCodes.Range("A1") _
.Offset(Application. _
WorksheetFunction _
.Match(Target.Value, _
wsCodes.Range("SUPPDESC"), 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
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to the Board!

Firstly, when posting code, please use Code Tags, as described here: How to Post Your VBA Code
It makes your code much easier to read, copy, and work with.

Your post is missing some key information. I think we need more of an explanation of your data (maybe some examples) and what you are ultimately trying to accomplish.

I see that you have two procedures:
Worksheet_Change
Worksheet_Change2


Note that "Worksheet_Change" event procedure codes are VBA procedures that will run automatically, under the right conditions, namely:
- VBA/Macros are enabled
- The code is placed in the proper Worksheet module
- The name of the procedure is EXACTLY "Worksheet_Change"

If your code is place in the proper Worksheet module, your first procedure would run automatically when triggered, but your second would not, as it does not meet the name requirement.
Also note that you cannot have multiple procedures in the same module with the same name. So if you wanted the code in your second procedure to also be triggered automatically, you either need to wrap the code into your first procedure, or have your first procedure make a call to the second.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top