I am not really using s as an input parameter for this code. For some reason the code only works with (s as string) in there. I came up with my own solution to this problem (any input/advice would be appreciated); however, it isn't very elegant:
Function abc(S As String) As String
Dim PREFIX(11) As String
Dim LENGTH(11) As String
Dim min As Long
Dim max As Long
Dim Full As String
Dim Part As String
Dim Ans As String
'Define Array Values
PREFIX(0) = "PRE1"
PREFIX(1) = "PRE2"
PREFIX(2) = "PRE3A"
PREFIX(3) = "PRE44444"
PREFIX(4) = "PRE5"
PREFIX(5) = "PRECCCCCCCCC"
...
' Choose Cell Value to Compare to Array
Full = Cells(1, 1).Text
' Obtain Array Text Length (LBound, UBound)
For j = LBound(PREFIX) To UBound(PREFIX)
LENGTH(j) = Len(PREFIX(j))
Next j
' Find Min and Max Text Length
min = 100
max = -100
For k = LBound(PREFIX) To UBound(PREFIX)
If LENGTH(k) > max Then max = LENGTH(k)
If LENGTH(k) < min Then min = LENGTH(k)
Next
' Find Match in Array
For i = min To max
Part = Left(Full, i)
If IIA(Part, PREFIX) = True Then
Ans = Application.WorksheetFunction.Index(PREFIX, Application.WorksheetFunction.Match(Part, PREFIX, 0))
abc = Ans
Else
End If
Next i
End Function
Function IIA(stringToBeFound As String, arr As Variant) As Boolean
IIA = Not IsError(Application.Match(stringToBeFound, arr, 0))
End Function
Bookmarks