Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default trim, chr(10)


If you want to simply remove ALL of them, you can use the Replace function
like this...

v = Replace(ActiveCell.value, vbLf, " ")

where vbLf is a pre-defined VB constant for Chr(10), which is the Line Feed
character. Note I have replaced the Line Feed characters with a blank space,
otherwise the text on the two lines of text would end up butted next to each
other (last word of one line next to the first word of the line below it).
If you don't want to remove them all, then you need to tell us more about
how they are placed in your text (and how you want them to look afterwards)
so we can figure out which to remove and which to leave.

--
Rick (MVP - Excel)


"Steve" wrote in message
...
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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


Hi Rick,
Thank you for the response.
Ok, something's not working here.....
Using your code--
v = replace(activecell.value, vbLf, " ")

It doesn't remove the vblf items.
I then tried vbCr, and vbNullChar, as well as vbCrLf in place of vbLf.
What am I missing here?


"Rick Rothstein" wrote:

If you want to simply remove ALL of them, you can use the Replace function
like this...

v = Replace(ActiveCell.value, vbLf, " ")

where vbLf is a pre-defined VB constant for Chr(10), which is the Line Feed
character. Note I have replaced the Line Feed characters with a blank space,
otherwise the text on the two lines of text would end up butted next to each
other (last word of one line next to the first word of the line below it).
If you don't want to remove them all, then you need to tell us more about
how they are placed in your text (and how you want them to look afterwards)
so we can figure out which to remove and which to leave.

--
Rick (MVP - Excel)


"Steve" wrote in message
...
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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


Ok, I just thought of something.....
in my case, I have 10 numeric characters, two vbLf characters, then 4
numeric characters, and then 3 more vbLf characters.
i.e.,
xxx-xxx-xxchr(10)chr(10)x.xxchr(10)chr(10)chr(10)

where the x, and hyphen, or dot are the elements I need to retain.
Would the replace look only at single vbLf's or does it look at ANY vbLf's,
and remove the?


"Rick Rothstein" wrote:

If you want to simply remove ALL of them, you can use the Replace function
like this...

v = Replace(ActiveCell.value, vbLf, " ")

where vbLf is a pre-defined VB constant for Chr(10), which is the Line Feed
character. Note I have replaced the Line Feed characters with a blank space,
otherwise the text on the two lines of text would end up butted next to each
other (last word of one line next to the first word of the line below it).
If you don't want to remove them all, then you need to tell us more about
how they are placed in your text (and how you want them to look afterwards)
so we can figure out which to remove and which to leave.

--
Rick (MVP - Excel)


"Steve" wrote in message
...
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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default trim, chr(10)


Record a macro when you
Select your range
Edit|Replace
what: ctrl-j (same as that alt-enter)
with: (leave blank or a space character if you want)
replace all
stop recording

Add this recorded code to the top of your existing macro that trims the values.



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.


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)

Hi Dave,
I tried as you said, and it spit out the message saying could not find
anything to replace. I then looked at the code it created, and tweaked it to
see which characters it could find-- nothing.....
I tried it 7 different ways
Any other ideas?

"Dave Peterson" wrote:

Record a macro when you
Select your range
Edit|Replace
what: ctrl-j (same as that alt-enter)
with: (leave blank or a space character if you want)
replace all
stop recording

Add this recorded code to the top of your existing macro that trims the values.



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.


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default trim, chr(10)


Share the code you tried.

If it worked on a selection, share the address of that selection.

And make sure that there were alt-enters in cells in that selected area.

Steve wrote:

Hi Dave,
I tried as you said, and it spit out the message saying could not find
anything to replace. I then looked at the code it created, and tweaked it to
see which characters it could find-- nothing.....
I tried it 7 different ways
Any other ideas?

"Dave Peterson" wrote:

Record a macro when you
Select your range
Edit|Replace
what: ctrl-j (same as that alt-enter)
with: (leave blank or a space character if you want)
replace all
stop recording

Add this recorded code to the top of your existing macro that trims the values.



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.


--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


Sub replaceTrim()

' replaceTrim Macro

Range("J14:J21").Select

Selection.Replace What:=Chr(9), Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

End Sub

Based on Rick's final post, I learned that it was chr 9. Once I got that,
this worked famously!!!!
Darn pesky non-descript character numbers. where's my shotgun.... oh, wait,
that's my computer... sigh...... ;-)



"Dave Peterson" wrote:

Share the code you tried.

If it worked on a selection, share the address of that selection.

And make sure that there were alt-enters in cells in that selected area.

Steve wrote:

Hi Dave,
I tried as you said, and it spit out the message saying could not find
anything to replace. I then looked at the code it created, and tweaked it to
see which characters it could find-- nothing.....
I tried it 7 different ways
Any other ideas?

"Dave Peterson" wrote:

Record a macro when you
Select your range
Edit|Replace
what: ctrl-j (same as that alt-enter)
with: (leave blank or a space character if you want)
replace all
stop recording

Add this recorded code to the top of your existing macro that trims the values.



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.

--

Dave Peterson


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default trim, chr(10)

VBA has some constants that make the code a bit easier to read.

vbTab (chr(9))
vbLf (chr(10))
vbCr (chr(13))

Chip Pearson has a very nice addin that will help determine what characters are
in the cell:
http://www.cpearson.com/excel/CellView.aspx

Steve wrote:

Sub replaceTrim()

' replaceTrim Macro

Range("J14:J21").Select

Selection.Replace What:=Chr(9), Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

End Sub

Based on Rick's final post, I learned that it was chr 9. Once I got that,
this worked famously!!!!
Darn pesky non-descript character numbers. where's my shotgun.... oh, wait,
that's my computer... sigh...... ;-)

"Dave Peterson" wrote:

Share the code you tried.

If it worked on a selection, share the address of that selection.

And make sure that there were alt-enters in cells in that selected area.

Steve wrote:

Hi Dave,
I tried as you said, and it spit out the message saying could not find
anything to replace. I then looked at the code it created, and tweaked it to
see which characters it could find-- nothing.....
I tried it 7 different ways
Any other ideas?

"Dave Peterson" wrote:

Record a macro when you
Select your range
Edit|Replace
what: ctrl-j (same as that alt-enter)
with: (leave blank or a space character if you want)
replace all
stop recording

Add this recorded code to the top of your existing macro that trims the values.



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.

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


Hi again.
Rick helped me find that it was actually chr 9. Your code worked once I got
that, so just wanted you to know.....
Again-- thank you for your help! It's deeply appreciated.
Best.

"Dave Peterson" wrote:

Record a macro when you
Select your range
Edit|Replace
what: ctrl-j (same as that alt-enter)
with: (leave blank or a space character if you want)
replace all
stop recording

Add this recorded code to the top of your existing macro that trims the values.



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.


--

Dave Peterson



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default trim, chr(10)

v = Replace(ActiveCell.value, Chr(10), Chr(32))

If this post helps click Yes
---------------
Jacob Skaria


"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.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default trim, chr(10)

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.


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


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.



  #14   Report Post  
Posted to microsoft.public.excel.programming
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.




  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


Ok, I tried this, and I have to be missing something, or doing it wrong.
The second line throws a compile error, stating "method not valid without
suitable object".



"Rick Rothstein" wrote:

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.






  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default trim, chr(10)


Did you run the code in the Immediate window... or did you try and put it in
a Sub/EndSub block in a code window? If the latter, you have to change the ?
(which VB probably changed to the key word Print) to the command Debug.Print
so that its output will go to the Immediate window.

--
Rick (MVP - Excel)


"Steve" wrote in message
...
Ok, I tried this, and I have to be missing something, or doing it wrong.
The second line throws a compile error, stating "method not valid without
suitable object".



"Rick Rothstein" wrote:

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.





  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)

Just tried the TRimAll.....
Nope, that didn't work either......


"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.



  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default trim, chr(10)

Using CHAR() and MID() function try and get which character it is and then
remove..

If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:

Just tried the TRimAll.....
Nope, that didn't work either......


"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.



  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)

you're going to laugh, or cry....
It returns a #value error.....
I first did char(mid(Num,StartNum,NumChar)) and got back #value error. I
checked the calculation steps, and it shows the right character, but then in
stepping through it just goes to the error.
I then tried char(right()), and char(left()).... same error


"Jacob Skaria" wrote:

Using CHAR() and MID() function try and get which character it is and then
remove..

If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:

Just tried the TRimAll.....
Nope, that didn't work either......


"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.


  #20   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default trim, chr(10)


If you have the data in cell A1; try the below formula to check the 5th
position
=CHAR(MID(A1,5,1))

In VBA use CHR()

If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:

you're going to laugh, or cry....
It returns a #value error.....
I first did char(mid(Num,StartNum,NumChar)) and got back #value error. I
checked the calculation steps, and it shows the right character, but then in
stepping through it just goes to the error.
I then tried char(right()), and char(left()).... same error


"Jacob Skaria" wrote:

Using CHAR() and MID() function try and get which character it is and then
remove..

If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:

Just tried the TRimAll.....
Nope, that didn't work either......


"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.




  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default trim, chr(10)


Hey Gord,
Rick helped me find that it was char 9. I modified your TrimAll from
DMcRitchie, to be chr(9) and it works.....
Thank you.
Best.

"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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TRIM Q Seanie Excel Worksheet Functions 3 November 17th 08 08:50 AM
VLOOKUP Trim vs. No Trim Kigol Excel Programming 2 October 3rd 07 05:14 PM
VBA Trim and Application.worksheetfunction.Trim Hari Prasadh Excel Programming 3 January 19th 05 02:22 PM
Trim or Len help (I think) Elaine[_5_] Excel Programming 5 July 3rd 04 11:02 PM
Trim like worksheet Trim Bob Phillips[_5_] Excel Programming 0 August 20th 03 07:10 PM


All times are GMT +1. The time now is 08:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"