0

Since I know, how to manage tih the TRIM function ddon to the last row, as advised here:

How to remove spaces from an entire Excel column using VBA?

or here:

Trim Cells using VBA in Excel

I want to do the same down to the last column.

In this case I prepared the following code:

  Sub trimit()
  Dim wks As Worksheet
  Dim lRow As Long, i As Long, lCol As Long

 Set wks = ThisWorkbook.ActiveSheet
  With wks
     lRow = .Columns("B:K").End(xlDown).Row
     lCol = Cells(1, Columns.Count).End(xlToLeft).Column
     For i = 1 To lRow
         .Cells(i, lCol).Value = trim(.Cells(i, lCol).Value)
     Next i
 End With
  End Sub

There is no error, but the code results fromenter image description here no reaction, or at most changes in column B only.

How can I apply the same for all the columns down to the last one?

Geographos
  • 827
  • 2
  • 23
  • 57

0 Answers0