Link to home
Start Free TrialLog in
Avatar of finnstone
finnstone

asked on

remove extra space at end of cell

i have 10k rows. some cells have a trailing space. some do not! how can i remove the space at the end
Avatar of Anthony Morast
Anthony Morast
Flag of United States of America image

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.
Avatar of Shums Faruk
Hi,

Which Column & start Row?
Avatar of finnstone
finnstone

ASKER

TRIM not working

column A start row 1
What's not working with TRIM?
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

ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
awesome
You're Welcome Finn! Glad I was able to help.
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.
that did not work
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.
Agree with lee, macro unnecessary and less efficient