Good evening, all,
I'm trying shorten names in a column by parsing the names and doing lookups on each word to return a possible abbreviation. I was doing a loop through each row (~200 words) to find a corresponding match. This seems to be taking a long time to complete.
So, now I am attempting to do the same thing using XLOOKUP instead of looping. The problem is that the following code refuses to compile yielding in the following error:
Compile error: Syntax Error
Function REPLACETEXTS(strInput As String) As String
Dim strTemp As String
Dim strFound As String
Dim tblTable As ListObject
Dim ws As Worksheet
Dim arrSplitString() As String
Dim strSingleString As String
Dim i As Long
Dim j As Long
Set ws = ThisWorkbook.Sheets("Abbreviations")
Set tblTable = ws.ListObjects("Abbrevs")
strTemp = ""
strInput = UCase(strInput)
strInput = Replace(strInput, "-", " ")
strInput = Replace(strInput, ",", " ")
strInput = Replace(strInput, ".", " ")
arrSplitString = Split(strInput, " ")
For i = LBound(arrSplitString, 1) To UBound(arrSplitString, 1)
' Loop through the table to find the lookup value
strFound = ""
' Attempting to replace this...
'For j = 1 To tblTable.ListRows.Count
' If tblTable.DataBodyRange(j, 1).Value = arrSplitString(i) Then
' strFound = tblTable.DataBodyRange(j, 2).Value
' Exit For
' End If
'Next j
' ... with this.
strFound = Application.WorksheetFunction.XLOOKUP( _
arrSplitString(i), _
Abbrevs[@OrigWord], _
Abbrevs[@Abbrev],"Error",0,1)
If strFound <> "" Then
strTemp = strTemp & " " & strFound
Else
strTemp = strTemp & " " & arrSplitString(i)
End If
Next i
If strTemp <> "" Then
REPLACETEXTS = Trim(strTemp)
Else
REPLACETEXTS = strInput
End If
End Function


xLookupwill always return a value, sostrFoundwill never be zero-length .... (once you fix your code to set the search and return ranges correctly)