Link to home
Start Free TrialLog in
Avatar of printmedia
printmedia

asked on

Left trim cells in column A Excel vba

Hi all.

I would like to remove any leading blank spaces for each cell in column A starting with A3 and going down as far as there is data using VBA.

I've tried the following but it's giving me an error: For Each may only iterate over a collection object or an array.

Dim r As Long
Dim Rng As Range

With Worksheets("Sheet1")
    
    r = .Range("A3" & Rows.Count).End(xlUp).Row
    For Each Rng In r
    Rng.Value = VBA.LTrim(Rng.Value)
    Next

End With

Open in new window


Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
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
try this

With Worksheets("Sheet1")
    .Range("A3").select
    Do

    .activecell.Value = VBA.LTrim(.activecell.Value)
 
	    .activecell.offset(1,0).activate
    loop until .activecell.value=""
End With

Open in new window