We help IT Professionals succeed at work.

remove extra space at end of cell

99 Views
Last Modified: 2017-03-16
i have 10k rows. some cells have a trailing space. some do not! how can i remove the space at the end
Comment
Watch Question

Anthony MorastSoftware Engineer

Commented:
The following steps should accomplish what you're trying to do,

  1. Insert a new column
  2. Insert Excel's
  3. TRIM
  4. function into the first row of the new column, with the input being the corresponding row of the existing column
  5. Copy the TRIM function down the page
  6. Copy the entire column you've just created with the TRIM function
  7. Paste the values in your pre-existing row, remember to Paste as "Values" rather than the function.
ShumsManaging Director/Excel VBA Developer
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
Hi,

Which Column & start Row?

Author

Commented:
TRIM not working

column A start row 1
Anthony MorastSoftware Engineer

Commented:
What's not working with TRIM?
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
You may try something like this and see if that works for you...

Sub RemoveSpaces()
Dim arr
arr = [Transpose(Trim(A1:A10000))]
Range("A1").Resize(UBound(arr)).Value = Application.Transpose(arr)
End Sub

Open in new window

Managing Director/Excel VBA Developer
CERTIFIED EXPERT
Distinguished Expert 2018
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
awesome
ShumsManaging Director/Excel VBA Developer
CERTIFIED EXPERT
Distinguished Expert 2018

Commented:
You're Welcome Finn! Glad I was able to help.
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
This is basically what Anthony said but in my opinion, his instructions were not clear.

1. Insert a new column next to the one you need to remove the spaces from (for the sake of argument, I'm going to assume Column A has the data and Column B is the new column AND that your data begins on row 1, making A1 your first piece of data).
2. in Column B, set the formula to =Trim(A1)
3. Copy that formula to the bottom of the sheet.
4. Select the entire column B and copy it.
5. Right click on Column A and use Paste Special and paste ONLY VALUES into Column A.

Modifications:
If you have other data at the top or bottom then don't select the entire column, just select the cells where the =Trim() is used. and then paste over the data using Paste Special on those selected columns.

Author

Commented:
that did not work
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
Really?  You tried mine in 15 seconds?  What didn't work?  a vb Macro can work as you've found, but in my opinion, it's WAY overkill for this simple function.  And you've spent zero time explaining HOW it didn't work.
Roy CoxGroup Finance Manager
CERTIFIED EXPERT

Commented:
Agree with lee, macro unnecessary and less efficient

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.