Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
QB QB is offline
external usenet poster
 
Posts: 57
Default How-To Remove Extra Spaces

I having to clean up messy user entries and would need some vba help on
how-to approach the following:

I am looping through a worksheet, row by row to get a column's value (this
works). Now I would need to perform a cleanup on the cell's value.

The user's have, in certain instances put in 2, 3 ... extra spaces in the
value (name of people). and I need to remove the extra space so that I am
left with firstname space lastname, instead of firstname space space
lastname, etc...

I might have
'John Smith'
'John Smith'

When I need to clean it up so I have
'John Smith'

This is my loop code, but I am lost on how to clean up the OpenedBy variable
For i = 2 To lstRow
OpenedBy = Range("J" & i).Text

'What would I need to do to remove extra spaces from the OpenedBy
variable?
Next i

Thank you,

QB
  #2   Report Post  
Posted to microsoft.public.excel.programming
QB QB is offline
external usenet poster
 
Posts: 57
Default How-To Remove Extra Spaces

Some more googling and I found a function that works great.

http://www.andreavb.com/tip000015.html

QB




"QB" wrote:

I having to clean up messy user entries and would need some vba help on
how-to approach the following:

I am looping through a worksheet, row by row to get a column's value (this
works). Now I would need to perform a cleanup on the cell's value.

The user's have, in certain instances put in 2, 3 ... extra spaces in the
value (name of people). and I need to remove the extra space so that I am
left with firstname space lastname, instead of firstname space space
lastname, etc...

I might have
'John Smith'
'John Smith'

When I need to clean it up so I have
'John Smith'

This is my loop code, but I am lost on how to clean up the OpenedBy variable
For i = 2 To lstRow
OpenedBy = Range("J" & i).Text

'What would I need to do to remove extra spaces from the OpenedBy
variable?
Next i

Thank you,

QB

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default How-To Remove Extra Spaces

Select the range and run the below macro..which will remove all extra spaces..

For Each cell In Selection
cell.Value = WorksheetFunction.Trim(cell.Text)
Next

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


"QB" wrote:

I having to clean up messy user entries and would need some vba help on
how-to approach the following:

I am looping through a worksheet, row by row to get a column's value (this
works). Now I would need to perform a cleanup on the cell's value.

The user's have, in certain instances put in 2, 3 ... extra spaces in the
value (name of people). and I need to remove the extra space so that I am
left with firstname space lastname, instead of firstname space space
lastname, etc...

I might have
'John Smith'
'John Smith'

When I need to clean it up so I have
'John Smith'

This is my loop code, but I am lost on how to clean up the OpenedBy variable
For i = 2 To lstRow
OpenedBy = Range("J" & i).Text

'What would I need to do to remove extra spaces from the OpenedBy
variable?
Next i

Thank you,

QB

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How-To Remove Extra Spaces

Use the Trim worksheet function, like this...

OpenedBy = WorksheetFunction.Trim(Range("J" & i).Text)

--
Rick (MVP - Excel)


"QB" wrote in message
...
I having to clean up messy user entries and would need some vba help on
how-to approach the following:

I am looping through a worksheet, row by row to get a column's value (this
works). Now I would need to perform a cleanup on the cell's value.

The user's have, in certain instances put in 2, 3 ... extra spaces in the
value (name of people). and I need to remove the extra space so that I am
left with firstname space lastname, instead of firstname space space
lastname, etc...

I might have
'John Smith'
'John Smith'

When I need to clean it up so I have
'John Smith'

This is my loop code, but I am lost on how to clean up the OpenedBy
variable
For i = 2 To lstRow
OpenedBy = Range("J" & i).Text

'What would I need to do to remove extra spaces from the OpenedBy
variable?
Next i

Thank you,

QB


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How-To Remove Extra Spaces

WorksheetFunction.Trim will do that in a single statement (see my other
response in this thread).

--
Rick (MVP - Excel)


"QB" wrote in message
...
Some more googling and I found a function that works great.

http://www.andreavb.com/tip000015.html

QB




"QB" wrote:

I having to clean up messy user entries and would need some vba help on
how-to approach the following:

I am looping through a worksheet, row by row to get a column's value
(this
works). Now I would need to perform a cleanup on the cell's value.

The user's have, in certain instances put in 2, 3 ... extra spaces in the
value (name of people). and I need to remove the extra space so that I
am
left with firstname space lastname, instead of firstname space space
lastname, etc...

I might have
'John Smith'
'John Smith'

When I need to clean it up so I have
'John Smith'

This is my loop code, but I am lost on how to clean up the OpenedBy
variable
For i = 2 To lstRow
OpenedBy = Range("J" & i).Text

'What would I need to do to remove extra spaces from the OpenedBy
variable?
Next i

Thank you,

QB


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 in a string John Excel Programming 3 February 4th 09 08:58 PM
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
how do I remove leading spaces and leave the remianing spaces w Debi Excel Worksheet Functions 6 February 28th 07 03:29 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 05:16 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"