I appreciate all the ideas, and while they will work, I'm still trying to improve performance (avoiding premature optimization as I go)
This is what I currently use, with 2 loops
'not using Ken's SpeedOn and SpeedOff yet
Sub WhatItIsNow()
Call WhatItIsNow_1(Worksheets("Sheet1").Range("A2:A8"), Worksheets("Sheet1").Range("C2:C11"))
End Sub
Sub WhatItIsNow_1(rSuffixs As Range, rSource As Range)
Dim aSuffix As Variant, aCompany As Variant
Dim iSuffix As Long, iCompany As Long
aSuffix = rSuffixs.Value
aCompany = rSource.Value
For iSuffix = LBound(aSuffix, 1) To UBound(aSuffix, 1)
aSuffix(iSuffix, 1) = UCase(aSuffix(iSuffix, 1))
For iCompany = LBound(aCompany, 1) To UBound(aCompany, 1)
If UCase(Right(aCompany(iCompany, 1), Len(aSuffix(iSuffix, 1)))) = aSuffix(iSuffix, 1) Then
aCompany(iCompany, 1) = Trim(Left(aCompany(iCompany, 1), Len(aCompany(iCompany, 1)) - Len(aSuffix(iSuffix, 1))))
End If
Next iCompany
Next iSuffix
rSource.Value = aCompany
End Sub
If I could use the built in Replace
Sub UsingBuiltinReplace()
Call UsingBuiltinReplace_1(Worksheets("Sheet1").Range("A2:A8"), Worksheets("Sheet1").Range("C2:C11"))
End Sub
Sub UsingBuiltinReplace_1(rSuffixs As Range, rSource As Range)
Dim rSuffix As Range
For Each rSuffix In rSuffixs.Cells
rSource.Replace What:=rSuffix.Value, Replacement:=vbNullString, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Next
End Sub
but that does not limit the test to just the end of the string
Actually what I do now is not perfect either, since sometimes a Company value will be trimmed twice
Since the built in Replace allows me to 'hit' an entire column, I was hoping a RegEx would allow that also, thus eliminating the inner loop
Paul