View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Convert String of 512 numbers to a range

Just another non-looping technique if you wish to use Regular Expressions.
It would be easy to adjust it for larger values. This assumes data is in
A1, and you wish to parse it to A1:IV2


Sub Demo()
'// = = = = = = = = = = = = = = = = = = = = = =
'// Dana DeLouis
'// Library Reference:
'// Microsoft VBScript Regular Expressions 5.5
'// = = = = = = = = = = = = = = = = = = = = = =

Dim s As String
Dim Matches As MatchCollection

s = [A1]
[A1:A2].NumberFormat = "@"

With New RegExp
.Global = True
.Pattern = ","
Set Matches = .Execute(s)
[A1] = Left$(s, Matches(Matches.Count \ 2).FirstIndex)
[A2] = Mid$(s, Matches(Matches.Count \ 2).FirstIndex + 2)
End With

Range("A1:A2").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, _
Semicolon:=False, _
Space:=False, _
Other:=False, _
Comma:=True
End Sub


--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Dana DeLouis" wrote in message
...
Just a different idea using text to columns. It splits the string onto
A1:A2, then uses text to column.

Sub Demo()
'// Dana DeLouis
Dim s As String
Dim half As Long
Dim v As Variant

s = [A1]
half = ((Len(s) - Len(Replace(s, ",", vbNullString))) \ 2) + 1
[A1:A2].NumberFormat = "@"
v = Split(Replace(Replace(s, ",", ";", 1, half), ";", ",", 1, half - 1),
";")
[A1] = v(0)
[A2] = v(1)

Range("A1:A2").TextToColumns _
Destination:=Range("A1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, _
Semicolon:=False, _
Comma:=True, _
Space:=False, _
Other:=False

End Sub


--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Kevin G" wrote in message
news:v0ZRb.29750$A7.8532@edtnps84...
Hello,

How would I convert a single cell string consiting of 512 values: 545,

565,
576, etc... to a range of 512 cells.

Thanks, Kevin Graham