I want to be able to delete all of the spaces from a group of cells so that the cell contents result in just being a string of information that I want. I have come up with a code but it doesn't work and I can't figure out whether I have to use a replace function or not
My code is:
Sub Tester()
Dim SearchString As String
Dim cell As Range
Dim LastRowSource As Long
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.ActiveSheet
SearchString = " " 'look for strings containing ( )
With ws1
LastRowSource = .Cells.Find(" ", [B2], , , xlByRows, xlPrevious).Row
For Each cell In .Range("B2:B" & LastRowSource)
If InStr(cell.Value, SearchString) > 0 Then
cell.Value = Replace(" ", "")
End If
Next cell
End Sub