Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Substitute() & Char() in Macro

I am trying to write a macro to remove white space in my excel spreadsheet. I
have following script but it says my sub or function not defined, but if I
use it in excel (not macro) it actually works. Any idea? Thanks.

Sub WhiteSpaceRemover()

Application.ScreenUpdating = False

For Each cell In Selection
cell.Value = Trim(Substitute(cell.Value, CHAR(160), CHAR(32)))
Next cell

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Substitute() & Char() in Macro

Substitute is a worksheet function. Try

Worksheetfunction.Substitute.

Or else try

VBscript function REPLACE()


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


"Jeremy" wrote:

I am trying to write a macro to remove white space in my excel spreadsheet. I
have following script but it says my sub or function not defined, but if I
use it in excel (not macro) it actually works. Any idea? Thanks.

Sub WhiteSpaceRemover()

Application.ScreenUpdating = False

For Each cell In Selection
cell.Value = Trim(Substitute(cell.Value, CHAR(160), CHAR(32)))
Next cell

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Substitute() & Char() in Macro

Somthing like the below..Are you sure it is 160 or Chr(10)

For Each cell In Selection
Cell.Value = WorksheetFunction.Trim(Replace(cell.Value, Chr(10), Chr(32)))
Next cell

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


"Jacob Skaria" wrote:

Substitute is a worksheet function. Try

Worksheetfunction.Substitute.

Or else try

VBscript function REPLACE()


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


"Jeremy" wrote:

I am trying to write a macro to remove white space in my excel spreadsheet. I
have following script but it says my sub or function not defined, but if I
use it in excel (not macro) it actually works. Any idea? Thanks.

Sub WhiteSpaceRemover()

Application.ScreenUpdating = False

For Each cell In Selection
cell.Value = Trim(Substitute(cell.Value, CHAR(160), CHAR(32)))
Next cell

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Substitute() & Char() in Macro

Hey Jacob,

Thanks for the solution, I was thinking to remove excessive space using
chr(160) but you reminded me to remove the chr(10) too. Thanks. =)

Jeremy

"Jacob Skaria" wrote:

Somthing like the below..Are you sure it is 160 or Chr(10)

For Each cell In Selection
Cell.Value = WorksheetFunction.Trim(Replace(cell.Value, Chr(10), Chr(32)))
Next cell

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


"Jacob Skaria" wrote:

Substitute is a worksheet function. Try

Worksheetfunction.Substitute.

Or else try

VBscript function REPLACE()


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


"Jeremy" wrote:

I am trying to write a macro to remove white space in my excel spreadsheet. I
have following script but it says my sub or function not defined, but if I
use it in excel (not macro) it actually works. Any idea? Thanks.

Sub WhiteSpaceRemover()

Application.ScreenUpdating = False

For Each cell In Selection
cell.Value = Trim(Substitute(cell.Value, CHAR(160), CHAR(32)))
Next cell

End Sub


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
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE.... max. limit 8 :( [email protected] Excel Discussion (Misc queries) 6 May 22nd 08 05:33 PM
FIND 1 char in cell of any 3 char =True Nastech Excel Discussion (Misc queries) 5 April 26th 08 02:17 PM
How to use substitute function in macro? Eric Excel Programming 4 March 16th 08 03:07 PM
How to substitute a comma with a newline char using Replace. edspyhill01 Excel Discussion (Misc queries) 9 July 30th 06 12:38 AM
8500 cells with phone number(7 char.), wishing to add area code (10 char.) [email protected] Excel Discussion (Misc queries) 6 March 10th 06 05:13 PM


All times are GMT +1. The time now is 12:30 PM.

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"