Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hidden characters

I am using this trimall macro for my data, the problem is
that it works fine for all the data except for cells that
have a value of 0032569. It is deleting the values 00
which is not good because if have several match formulas
in place. Is there any way to trimall and still keep the
00?


Sub TrimALL()
Application.ScreenUpdating = False
Cells.Select
'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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Hidden characters

When you do that mass change (chr(160) to chr(32)--the non-breaking space to a
regular space), excel sees it as you typing in a numeric entry. And it forgives
the extra leading or trailing space.

This might be better for you:

Option Explicit

Sub TrimALL2()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range

On Error Resume Next 'in case no text cells in Selection
For Each cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
cell.Value = Application.subsitute(cell.Value, Chr(160), Chr(32))
cell.Value = Application.Trim(cell.Value)
Next cell
On Error GoTo 0
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Diana wrote:

I am using this trimall macro for my data, the problem is
that it works fine for all the data except for cells that
have a value of 0032569. It is deleting the values 00
which is not good because if have several match formulas
in place. Is there any way to trimall and still keep the
00?

Sub TrimALL()
Application.ScreenUpdating = False
Cells.Select
'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


--

Dave Peterson

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
View hidden characters fitou_learn Excel Discussion (Misc queries) 6 April 22nd 23 10:11 AM
Hidden Characters? GL Excel Discussion (Misc queries) 2 September 14th 08 02:07 PM
Trim hidden characters? robotman Excel Worksheet Functions 3 October 20th 07 12:00 AM
Viewing hidden characters BT Connect Excel Discussion (Misc queries) 1 January 11th 07 04:20 PM
Help! Can't get rid of hidden characters tragopanic Excel Discussion (Misc queries) 1 July 13th 05 10:20 PM


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

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

About Us

"It's about Microsoft Excel"