VERY new to VBA, first class I have taken so far. I am getting Compile error: "Ambiguous name detected: identifier" when trying to run the assignment below. The assignment doesn't allow you to change the name of subs or functions. The "Identifier" is both a sub and a function. If I change the sub name to "IdentifierS I am able to F8 through the code fine. Is there a way to run the function as named or did I miss something? Thank you in advance.
Option Explicit
Dim ColorRow As Integer, NameRow As Integer, ID As String
' NOTE: For highlighting, use .ColorIndex = 4
' For example, Range("A1").Interior.ColorIndex = 4 would color cell A1 green
Sub HighlightRows(ID)
Range(Cells(ColorRow, 1), Cells(ColorRow, 3)).Select
With Selection.Interior
.ColorIndex = 4
End With
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
ID = "Y4-824X"
MsgBox "The identifier is " & Identifier(ID) & " and the key is " & Key(ID)
End Sub
Sub Identifier()
Dim ID As String, nr As Integer, i As Integer
nr = WorksheetFunction.CountA(Columns("A:A")) - 1
For i = 1 To nr
ID = Range("A" & i + 1)
If Identifier(ID) = Range("F2") And Key(ID) = Range("F3") Then
ColorRow = i + 1
HighlightRows (ID)
End If
Next i
End Sub
Function Identifier(ID) As String
Identifier = Left(ID, 1)
End Function
Function Key(ID) As String
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