Parsing a string
here's something you can try:
Sub test()
Dim ws As Worksheet
Dim i As Long
Dim sWord As Variant
Set ws = Worksheets("Sheet1")
i = 1
sWord = Split(ws.Range("A1").Value, " ")
For i = 0 To UBound(sWord)
ws.Range("h" & i + 1).Value = sWord(i)
Next
End Sub
--
Gary
Excel 2003
wrote in message
...
Hi, I need some help on this.
I have sentence i column "A" row 1. This can be a variable length.
In column "H" I have the column set to receive for now 20 characters.
I'm trying to take the entire sentence and parse it to rows in column
"H"
Each row would have whole words.
This is the start of the code I'm working with.
Sub Mytest()
LENGTHOFCELL = Len(ActiveCell)
cnt = 20 '' nr of characters
cnt1 = 1''set first character
rcnt = 1''row nr
Do While cnt < LENGTHOFCELL
mystring = Mid(ActiveCell.Value, cnt1, 20)
Cells(rcnt, 8).Value = firstname
cnt1 = cnt + 1
cnt = cnt + 20
rcnt = rcnt + 1
mystring = ""
Loop
End Sub
This works some what. I know that this code will exit when the cnt
exceeds the LENGTHOFCELL.
Any help would be appreciated.
|