Solved

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

Posted on 2013-05-13
2
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

752 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