Hello,
I have searched and t this point have not found anything that is very helpful with the substitute function in VBA. I am unsure why but sometimes TRIM does not remove the space after a the word in a cell.
Someone gave me the following which seems to work
=TRIM(SUBSTITUTE(A1,CHAR(160),CHAR(32)))
However I want to create a personal macro that will run this in each cell that is currently selected. For some reason the below code I have built out so far does not work. What am I missing or is there an easier way altogether? I believe the problem occurs with the substitute. Any help appreciated.
I have searched and t this point have not found anything that is very helpful with the substitute function in VBA. I am unsure why but sometimes TRIM does not remove the space after a the word in a cell.
Someone gave me the following which seems to work
=TRIM(SUBSTITUTE(A1,CHAR(160),CHAR(32)))
However I want to create a personal macro that will run this in each cell that is currently selected. For some reason the below code I have built out so far does not work. What am I missing or is there an easier way altogether? I believe the problem occurs with the substitute. Any help appreciated.
Code:
Sub tested()
Dim cell As Range
For Each cell In Selection
Selection.Value = TRIM(Substitute(Selection.Value, Chr(160), Chr(32)))
Next
End Sub