Thread: trim, chr(10)
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default trim, chr(10)

Give this a try... Select one of the cell that contains your suspicious
character and then go to the Immediate window in the VB editor and execute
these two lines (copy/paste them and then hit Enter on each line)...

S = ActiveCell.Value
For X = 1 to Len(S) : ? Asc(Mid(S, X, 1)) : Next

This will list out the ASCII character codes for each character in your
cell... just count over to the first non-recognizable letter and see what
the code is for that character.

--
Rick (MVP - Excel)


"Steve" wrote in message
...
Hi Gord,
No, I'm not sure. And after trying Rick's idea, I'm really thinking that
they're something else, other than chr(10), or chr(13)


"Gord Dibben" wrote:

Are you sure they are chr(10) characters?

Perhpas they are chr(160)

Try David McRitchie's TRIMALL macro.

Sub TrimALL()
'David McRitchie 2000-07-03 mod 2000-08-16 join.htm
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim Cell As Range
'Also Treat CHR 0160, as a space (CHR 032)
Selection.Replace what:=Chr(160), replacement:=Chr(32), _
lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
'Trim in Excel removes extra internal spaces, VBA does not
On Error Resume Next 'in case no text cells in selection
For Each Cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
Cell.Value = Application.Trim(Cell.Value)
Next Cell
On Error GoTo 0
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP

On Thu, 9 Jul 2009 07:34:02 -0700, Steve

wrote:

morning all.
I'm trying to clean out some extra spaces in my data.
Using AutoCAD 2009, I extracted some data into an excel spreadsheet.
(Autodesk has created a dataextraction tool for the latest version)

The data set that I'm trying to clean up has a bunch of chr(10) elements
in
it, and I'd like to remove them. Well, let me restate that-- there are
multiple blank space characters in the strings that I want to remove.
I've tried trim, but it appears to be treating the chr(10) elements as
valid
string components. I've also tried right() and it too is picking up the
chr(10) elements.

How can I clean the chr(10) elements out?

Here's my present code (It's something I got from Gary's Student either
late
last year, or earlier this year, and made one modification to-- adding
trim)--

Dim v As String, val As Double
While ActiveCell.value < ""
v = ActiveCell.value
v = Trim(v)
val = Right(v, 4)
ActiveCell.Offset(0, 1).value = val
ActiveCell.Offset(1, 0).Select
Wend


Thank you for your helps.