Solved

Excel 2010 VBA - How to delete excess spaces inside of a cell

Posted on 2013-05-13
2
306 Views
Last Modified: 2013-05-13
I have a group of cells (A1:A300) that contain names.  However, immediately preceeding the names are a bunch of spaces.  I don't know how they got in there but I would like to have some way of deleting the spaces and retaining the names.
How can I do this using VBA?
Or maybe I don't need vba?
0
Comment
Question by:brothertruffle880
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39162995
Try using a formula like:
=TRIM(SUBSTITUTE(A1,CHAR(160)," "))

The ASCII 160 non-breaking space is frequently found in data imported from elsewhere and cannot be removed by TRIM. That's why the SUBSTITUTE function is wrapped inside the formula--to convert those ASCII 160 non-breaking spaces to regular ASCII 32 spaces.

TRIM removes all leading and trailing ASCII 32 spaces, and all but one space between words.
0
 

Author Comment

by:brothertruffle880
ID: 39163354
Perfect.  Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question