The Batch ID has a two-digit code to the left of the hyphen and a 3- or 4-digit code to the right of the hyphen. The first letter of the Batch ID is known as the Identifier and the leading number of the 3- or 4-digit code to the right of the hyphen is known as the Key. For example, in the Batch ID "N9-363B", the Identifier is "N" and the Key is 3:
Your goal is to create a subroutine that allows the user to select the Identifier from a drop-down menu in cell F2 and the Key from a drop-down menu in cell F3 (these drop-down/data validation menus are already available in the starter file) and any rows of the data (columns A, B, and C) whose Batch ID meets those criteria will be highlighted GREEN.
So far I could do till here only, please help
Sub HighlightRows()
Dim nr As Integer, i As Integer, Identifier() As String, Key() As String, ID As String, Z As String, Y As String
Reset
nr = WorksheetFunction.CountA(Columns("A:A"))
For i = 1 To nr
ID = Range("A" & i + 1)
Y = Key(ID)
Z = Identifier(ID)
If Z = Range("identifier") & Y = Range("key") Then Range("A:A").Interior.ColorIndex = 4
Next i
End Sub
Sub Example()
' This is just to show how the Identifier and Key functions below can be utilized in VBA code
Dim ID As String, i As Integer, nr As Integer
nr = WorksheetFunction.CountA(Columns("A:A"))
ID = Range("A" & i + 2)
MsgBox "The identifier is " & Identifier(ID) & " and the key is " & Key(ID)
End Sub
Function Identifier(ID As String) As String
Identifier = Left(ID, 1)
End Function
Function Key(ID As String) As Integer
Key = Left(Mid(ID, 4, 4), 1)
End Function
Sub Reset()
' Obtained through a macro recording:
With Cells.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Bookmarks