The code is in the Worksheet_Change event procedure, so it runs when
something on this worksheet changes, such as selecting an item from one
of the data validation dropdowns in column B.
Target is the cell, or cells, that have been changed.
First, the code counts the number of cells selected, and stops running
if more than one cell is selected.
If Target.Cells.Count > 1 Then GoTo exitHandler
Next, the code checks which column the Target cell is in. If the column
number is 2 (column B), then the rest of the code runs.
If Target.Column = 2 Then
Next, it checks the value entered in the Target cell. If the value is ""
(an empty string, which means no value), then the code stops running.
If Target.Value = "" Then GoTo exitHandler
Next EnableEvents is turned off, so no other code will be triggered by
this code.
Application.EnableEvents = False
Next, the value in the Target cell is changed to the product code that
matches the selected product name. ProdList is a named range on the
Codes sheet.
The Match function is used to find the selected product in that range,
and return a number. For example, Product A, would return a 1, because
it's the first item. That number is used in the Offset property.
In this example, the Offset property finds the value in the cell, that's
1 row down, and zero columns over from cell A1 on the Codes sheet.
Target.Value = Worksheets("Codes").Range("A1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ProdList"), 0), 0)
Finally, EnableEvents is turned on, so the events will continue to work
in Excel.
Application.EnableEvents = True