I am trying to replace spaces with dashes (-). When I am going through my characters and every time I find a space between them I want to replace them with a -. For instance if I have a string: A B, it should be converted into A-B. Here is my code:
Sub prac()
Dim x As String, a As Long, lastrow As Long, i As Long
Dim xcell As String
x = "-"
a = 1
lastrow = Worksheets("Sheet1").UsedRange.Rows.Count + 1
For i = a To lastrow
xcell = Worksheets("Sheet1").Range("A" & i)
If InStr(1, xcell, "") > 0 Then
Worksheets("Sheet1").Range("A" & i) = strReplace("xcell", "", x)
End If
Next i
End Sub