I have some code that is supposed to Trim the values of cells quickly, taken from here:
https://www.thespreadsheetguru.com/the-code-vault/a-fast-way-to-clean-trim-cell-values-with-vba-code
<code>
However, I see this happening when I debug the program, and I don't know why:
<code>
that returns this in the Immediate Window:
<code>
Why does the Debug.Print .Worksheets("Sheet1").Cells(1, 1) return an extra space at the beginning of the value? This is preventing me from using Application.Match properly in some later code. I know can Trim the cell individually and it removes this space, but that would significantly slow down my code if I had to loop through individual cells.
https://www.thespreadsheetguru.com/the-code-vault/a-fast-way-to-clean-trim-cell-values-with-vba-code
<code>
Rich (BB code):
With ActiveWorkbook.Worksheets(WSname)
.Activate
Dim rng As Object
Dim Area As Object
'Weed out any formulas from selection
Set rng = Range(Cells(1, 1), Cells(wsNameallRows, wsNameallColumns)).SpecialCells(xlCellTypeConstants)
'Trim and Clean cell values
For Each Area In rng.Areas
Area.Value = Evaluate("IF(ROW(" & Area.Address & "),CLEAN(TRIM(" & Area.Address & ")))") 'this only deletes leading and trailing spaces
Next Area
End With
</code>
However, I see this happening when I debug the program, and I don't know why:
<code>
Rich (BB code):
With ActiveWorkbook
Debug.Print varPrdOrd
Debug.Print PrdOrd
Debug.Print .Worksheets("Sheet1").Cells(1, 1)
Debug.Print .Worksheets("Sheet1").Cells(1, 1).Text
Debug.Print Len(.Worksheets("Sheet1").Cells(1, 1))
Debug.Print Len(.Worksheets("Sheet1").Cells(1, 1).Text)
End With
</code>
that returns this in the Immediate Window:
<code>
Rich (BB code):
20730642
20730642
20730642
20730642
8
8
</code>
Why does the Debug.Print .Worksheets("Sheet1").Cells(1, 1) return an extra space at the beginning of the value? This is preventing me from using Application.Match properly in some later code. I know can Trim the cell individually and it removes this space, but that would significantly slow down my code if I had to loop through individual cells.
Last edited: