Populating Cells from a delimited string

S

sunmax

Hi
I am trying to fill the values parsed from a delimited string on t
Excel Spread sheet. Being relatively new to VBA programming, I woul
appreciate it if someone would tell me how to populate the cells in
spread sheet with the values parsed from the string.
Thanks
-
 
J

jeff

HI,

assuming you have ABC-123-Done in cell A1 for example,
the following code will parse out ABC, 123, Done and
put in C1, C2, C3. Play with it to expand capabilities
to do what you need.
(I know it's not sophisticated, but it's a start)

Sub ParseIt()
Dim StrToParse As String
Dim c As Integer
Dim x As String
StrToParse = Range("A1").Value
x = InStr(1, StrToParse, "-")
Do While x
If x Then
NewRow = NewRow + 1
leftone = Left(StrToParse, x - 1)
StrToParse = Right(StrToParse, Len(StrToParse) - x)
Range("C" & NewRow) = leftone
x = InStr(1, StrToParse, "-")
End If
Loop
NewRow = NewRow + 1
Range("C" & NewRow) = StrToParse
End Sub

jeff
 
D

Dave Peterson

If the data is already in a cell(s), look at Data|text to columns.

If the data is in a text file, you should be able to open it (File|open) and see
the text to columns wizard.

If you need a macro, recording one when you do it manually will get you the
basic code.
 
Top