TRIM function not working

Manolocs

Active Member
Joined
Mar 28, 2008
Messages
340
I have no idea why this happens, I already followed threads from this forum and use the following formulas and macros but still can not get ride of the spaces in front of the cells :(
Any help is more than welcome.
:ROFLMAO:

=TRIM(A1)
=SUBSTITUTE(A1,CHAR(160),"")
=TRIM(SUBSTITUTE(D1,CHAR(160),CHAR(32)))
Code:
Sub RemoveLeadingSpace()
'Updateby20131129
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    Rng.Value = VBA.LTrim(Rng.Value)
Next
End Sub
 
Last edited by a moderator:
Getting late here in Oz - but this seems to work:

Code:
Option Explicit
Sub Macro2()

    Dim lngLastRow As Long
    Dim rngMyCell As Range
    Dim i As Integer
    
    lngLastRow = Range("A:E").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    Application.ScreenUpdating = False
    
    For Each rngMyCell In Range("A1:E" & lngLastRow)
        If Len(rngMyCell) > 0 And IsNumeric(rngMyCell) = False And rngMyCell.HasFormula = False Then
            rngMyCell.Replace Chr(160), "", xlPart
            rngMyCell = Trim(rngMyCell)
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True

End Sub

Robert
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I really don't know what to say. I don't get the same values from CODE(B1) as you do, and the code I have presented works for me.

You're not using a Mac, are you?

Yes I am. is there a problem? I am running many other macros and VBA with no problem.
 
Upvote 0
There are many weird differences between Mac and PC. Are you using Office 2011 or 2016 (or something even earlier)?
 
Upvote 0
Don't worry - it's always good for me to learn of a new Mac vs PC quirk! :)
 
Upvote 0

Forum statistics

Threads
1,216,723
Messages
6,132,317
Members
449,718
Latest member
Marie42719

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