inactiveUser333473
New Member
- Joined
- Jul 10, 2015
- Messages
- 45
Hi,
I'm using the following VBA. I want to delete any superfluous spaces without deleting my vlookup formulas but when I run this macro, it deletes everything except cell value.
How do I retain formulas in cells?
VBA:
Sub SelectRange_Trim()
'Trim spaces
Dim MyCell As Range
On Error Resume Next
Selection.Cells.SpecialCells(xlCellTypeConstants, 100).Select
For Each MyCell In Selection.Cells
MyCell.Value = RTrim(MyCell.Value)
MyCell.Value = LTrim(MyCell.Value)
Next
On Error GoTo 0
End Sub
I'm using the following VBA. I want to delete any superfluous spaces without deleting my vlookup formulas but when I run this macro, it deletes everything except cell value.
How do I retain formulas in cells?
VBA:
Sub SelectRange_Trim()
'Trim spaces
Dim MyCell As Range
On Error Resume Next
Selection.Cells.SpecialCells(xlCellTypeConstants, 100).Select
For Each MyCell In Selection.Cells
MyCell.Value = RTrim(MyCell.Value)
MyCell.Value = LTrim(MyCell.Value)
Next
On Error GoTo 0
End Sub