How to remove spaces from a word in a cell

1 view
Skip to first unread message

Jerry

unread,
Jan 15, 2007, 1:05:48 AM1/15/07
to excel vba
I want to do it automatically for a group of cells.

for example, if the word in a cell is "a b c", after spaces are
removed, the new word in the cell will be "abc"


how to do it by using VBA? thanks!

Scott Winter

unread,
Jan 15, 2007, 11:13:00 AM1/15/07
to exce...@googlegroups.com
There is a funtion called "Trim" I believe that would
accomplish this for you
--- Jerry <jsu...@gmail.com> wrote:


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

crfer...@gmail.com

unread,
Jan 18, 2007, 9:35:47 AM1/18/07
to excel vba
Actually, the trim function only takes the leading or trailing spaces
from a string. To remove all spaces from any given word or sentence,
use the Strings.Replace function in VBA. An example on using it would
be:

Dim s as string
s = "t h e str i ng"
s = Strings.Replace(s, " ", "")

The resulting s would be "thestring". The syntax is:
Strings.Replace(yourstring, valuetolookfor, valuereplacedwith). Check
VBA help for more details. I don't know of a way to do it on an entire
group of cells at one time, but you could easily loop through the set
of cells and apply that function.

Reply all
Reply to author
Forward
0 new messages