Hei.
I've been trying different things but I can't find what the issue is.
When I use code below as is, I get run-time error -2147417848 (80010108).
When I remove line 5 (the one with Trim function), it works ok.
I test it manually adding spaces in from and after the text value in a cell.
I've been trying different things but I can't find what the issue is.
When I use code below as is, I get run-time error -2147417848 (80010108).
When I remove line 5 (the one with Trim function), it works ok.
I test it manually adding spaces in from and after the text value in a cell.
Code:
If (Target.Column = 2) Then Application.ScreenUpdating = False
lastRowB = ActiveSheet.Range("B" & ActiveSheet.Rows.Count).End(xlUp).Row
For i = 2 To lastRowB
ActiveSheet.Range("B" & i) = Trim(ActiveSheet.Range("B" & i))
If (Len(ActiveSheet.Range("B" & i)) = Len(Replace(ActiveSheet.Range("B" & i), " ", ""))) Then
ActiveSheet.Range("C" & i) = ActiveSheet.Range("B" & i)
Else
ActiveSheet.Range("C" & i) = Replace(ActiveSheet.Range("B" & i), _
String(Len(ActiveSheet.Range("B" & i)) - Len(Replace(ActiveSheet.Range("B" & i), " ", "")), " "), _
String(9 - (InStr(ActiveSheet.Range("B" & i), " ") - 1), " "))
End If
Next i
Application.ScreenUpdating = True
End If