Trim Help

southcoast

New Member
Joined
Jan 17, 2017
Messages
2
Hi all, I am a new member, don’t know if anyone can help. I am trying to find a “Formula” or VBA, (preferably a formula), to trim a complete"worksheet" in Mac Excel 2016, I am ok on a column, thats not a problem but when I have 12 columns some times 15 columns in a table/worksheet it would be nice to TRIM all in one go instead of 1 column at a time. I look forward to any reply, Regards, Roger.
 
I have no experience on a Mac, but, here is a macro solution for you to consider on a PC, that does not do any looping thru all the cells in the used range of a worksheet.
...
Code:
Sub TrimMeV2()
' hiker95, 01/17/2017, ME986219
Dim lr As Long, lc As Long
Application.ScreenUpdating = False
With ActiveSheet
  lr = .Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
  lc = .Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
  With .Range(.Cells(1, 1), .Cells(lr, lc))
    .Value = Evaluate("IF(ISTEXT(" & .Address & "),TRIM(" & .Address & "),REPT(" & .Address & ",1))")
  End With
  .Columns(1).Resize(, lc).AutoFit
End With
Application.ScreenUpdating = True
End Sub
Wonderful!!!
A very great great thank you for this macro, hicker95 !
I've just registered on MrExcel just to thank you!
I owe you a bottle of good red wine!
(y)
 
Last edited by a moderator:
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Wonderful!!!
A very great great thank you for this macro, hicker95 !
I've just registered on MrExcel just to thank you!
I owe you a bottle of good red wine!

elpablo,

Welcome to the MrExcel forum.

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,586
Members
449,520
Latest member
TBFrieds

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top