Reputation: 11697
I have no idea what is happening, but I have cells that contain what appears to be a return carriage. I have tried TRIM()
, CLEAN()
, =SUBSTITUTE(A1,CHAR(10),"")
and a number of macros to remove these characters.
The only way to remove these characters it to get the cell active, click delete near the last character, and click enter.
Is there something I'm missing? Is there a way to programatically do this?
Upvotes: 6
Views: 51855
Reputation: 439
Note: Cntrl+J here captures the carriage return cells.
Upvotes: 0
Reputation:
I have tried
ws.Cells(i, j) = Replace(ws.Cells(i, j), Chr(13), "")
and succeed.
Upvotes: 1
Reputation: 21
An easier solution is find replace: for find press alt and the numbers 010 at the same time (on the 10 keypad) and then replace with a space.
You can do this as a bulk replace by just highlighting the cells that contain the carriage breaks.
Upvotes: 2
Reputation: 4972
The following macro will remove all non-printable characters and beginning and ending spaces utilising the Trim()
and Clean()
functions:
Sub Clean_and_Trim_Cells()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim s As String
For Each c In ActiveSheet.UsedRange
s = c.Value
If Trim(Application.Clean(s)) <> s Then
s = Trim(Application.Clean(s))
c.Value = s
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Upvotes: 15