Microsoft Office Tutorials and References
In Depth Information
Because The Garden Company uses a consistent naming system for its products, you can cre
ate a procedure to determine the category of each product ordered. In this naming system,
the first two characters of an item’s identification code indicate to which category the item
belongs ( TL for Tools, SP for Supplies, and FN for Furniture). So, rather than require a user
to enter the category, the procedure could do it for them.
Note The data in the worksheet has all uppercase letters, so the entries in the proce
dure’s Case statements look for uppercase-only category codes.
Public Sub NoteCategory()
Dim MyCell As Range
Dim strFirst, strLast, strAllCells, strCategory As String
strFirst = InputBox("Enter the address of the first cell in the OrderItem
strLast = InputBox("Enter the address of the last cell in the OrderItem column.")
strAllCells = strFirst & ":" & strLast
For Each MyCell In Range(strAllCells).Cells
strCategory = Left(MyCell.Value, 2)
Select Case strCategory
ffset(0, 1).Value = "Tools"