joharmenezes
Member
I have the following VBA code:
Sub NumberSplit()
For Each Cell In Range("a1:a22")
Dim count As Integer
count = 0
AreThereSpaces = 0
col = 0
CellValue = CStr(Cell.Value)
On Error Resume Next
For i = (count + 1) To Len(CellValue)
AreThereSpaces = WorksheetFunction.Find(" ", CellValue, i)
If AreThereSpaces > 0 Then
LotteryNum = Mid(CellValue, i, AreThereSpaces - 1)
col = col + 1
PrintOnTheScreen LotteryNum, Cell.Row, Cell.Column + col
count = count + AreThereSpaces
End If
Next i
Next Cell
End Sub
Sub PrintOnTheScreen(NumToPrint, RowNum, ColNum)
Range(Cells(RowNum, ColNum), Cells(RowNum, ColNum)).Value = NumToPrint
End Sub
I am trying to split characters in a string whenever a space is encountered and paste the splits in adjacent rows
For example:
If cell A1 has "ab cd ef"
then the cells should be , B1="ab", C1="cd", D1="ef"
Thanks
Sub NumberSplit()
For Each Cell In Range("a1:a22")
Dim count As Integer
count = 0
AreThereSpaces = 0
col = 0
CellValue = CStr(Cell.Value)
On Error Resume Next
For i = (count + 1) To Len(CellValue)
AreThereSpaces = WorksheetFunction.Find(" ", CellValue, i)
If AreThereSpaces > 0 Then
LotteryNum = Mid(CellValue, i, AreThereSpaces - 1)
col = col + 1
PrintOnTheScreen LotteryNum, Cell.Row, Cell.Column + col
count = count + AreThereSpaces
End If
Next i
Next Cell
End Sub
Sub PrintOnTheScreen(NumToPrint, RowNum, ColNum)
Range(Cells(RowNum, ColNum), Cells(RowNum, ColNum)).Value = NumToPrint
End Sub
I am trying to split characters in a string whenever a space is encountered and paste the splits in adjacent rows
For example:
If cell A1 has "ab cd ef"
then the cells should be , B1="ab", C1="cd", D1="ef"
Thanks