Solved

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

Posted on 2013-05-13
2
299 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

776 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