Home » excel » excel – Using a Trim function to remove extra characters not needed

excel – Using a Trim function to remove extra characters not needed

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to trim all of the cells that have data in column C to the left most 9 characters.

Sub TrimColumns()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row

     If LastRow > Columns("B").Row Then
        Range("C2:C" & LastRow).LTrim(1,9) ' getting syntax error on this line 
     End If 
End Sub

Range("C2:C" & LastRow).LTrim(1,9) ‘ getting syntax error on this line

How to&Answers:

Just use Left?

Cells(1,1).value = Left(Cells(1,1).value,9)

This would be looped down the range:

For i = 1 to LastRow Step 1
    Cells(i,3).value = Left(Cells(i,3).value,9)
Next i