Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Removing extra spaces in a string

What's a quick way to remove multiple spaces between words in a string?

I tried ProjectName = Replace(ProjectName, " ", " "), but this sometimes
leaves multiple spaces between words in ProjectName.

I appreciate your help, -John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Removing extra spaces in a string

Application.Trim(string) to remove extra spaces


Gord Dibben MS Excel MVP

On Wed, 4 Feb 2009 11:41:59 -0800, John
wrote:

What's a quick way to remove multiple spaces between words in a string?

I tried ProjectName = Replace(ProjectName, " ", " "), but this sometimes
leaves multiple spaces between words in ProjectName.

I appreciate your help, -John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Removing extra spaces in a string

if you have 3 spaces your code will only remove one of the spaces still
leaving two try this

'Test for 2 blanks in a row
Do while Instr(ProjectName, " ") 0 then
ProjectName = Replace(ProjectName, " ", " ")
Loop


"John" wrote:

What's a quick way to remove multiple spaces between words in a string?

I tried ProjectName = Replace(ProjectName, " ", " "), but this sometimes
leaves multiple spaces between words in ProjectName.

I appreciate your help, -John

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Removing extra spaces in a string

No "Then" keyword required in a Do statement. Also, while some may not
consider it as clear, you don't have to test the InStr function's return
value for being greater than 0... VB will consider any non-zero value for a
logical expression as True.

Do While InStr(ProjectName, " ")
ProjectName = Replace(ProjectName, " ", " ")
Loop

--
Rick (MVP - Excel)


"Joel" wrote in message
...
if you have 3 spaces your code will only remove one of the spaces still
leaving two try this

'Test for 2 blanks in a row
Do while Instr(ProjectName, " ") 0 then
ProjectName = Replace(ProjectName, " ", " ")
Loop


"John" wrote:

What's a quick way to remove multiple spaces between words in a string?

I tried ProjectName = Replace(ProjectName, " ", " "), but this sometimes
leaves multiple spaces between words in ProjectName.

I appreciate your help, -John


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
removing extra spaces BVZ Excel Discussion (Misc queries) 2 October 29th 08 07:21 PM
removing extra spaces in excel Seemore Excel Programming 1 August 4th 08 10:09 PM
Removing 2 extra spaces in front of dates in imported excel doc Hannah Excel Discussion (Misc queries) 4 April 12th 06 07:37 PM
Removing random extra spaces jermsalerms Excel Discussion (Misc queries) 3 January 18th 06 04:40 PM
deleting extra spaces in a string Eric[_16_] Excel Programming 6 December 3rd 03 10:50 PM


All times are GMT +1. The time now is 04:13 PM.

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"