I have a column of full names that I would like to replace with initials.
I am currently doing this:
Dim n As Long
Dim varray As Variant
Dim FullNameRange As Range
Dim FullName As String
varray = Range(NDLstaffCol & FirstLineItemRow & ":" & staffCol & LastRow + 1)
For n = FirstLineItemRow To UBound(varray, 1)
Set FullNameRange = ActiveSheet.Range(staffCol & n)
FullName = FullNameRange.Value
FullNameRange = Left(FullName, 1) & Mid$(FullName, InStr(FullName, " ") + 1, 1)
Next
Where LastRow refers to the last record as a global variable.
This takes a long time to process compared to other subroutines in the same module.
Is there a better way to do this?
For reference, I never know the full names so a hard-coded find/replace would not work. There are <500 records.
O(n)which can't be improved upon (at least in this universe). Have you tried running outside of the debugger? Does it run just as slowly in debug mode and normally? Have you tried rewriting it in C#/.NET using the .NET Office SDK? Does it run faster if you minimize Excel as you run it? What version of Excel are you using?