Solved

Split String to Array

Posted on 2015-01-02
5
185 Views
Last Modified: 2015-01-02
How to write a VBA to string a string into chars ?

Input string :
   17DFA0.08 18DFB0.23 92XGG1.49 1XRH0.09 1XGT1.34

Output array :
17DFA0.08
18DFB0.23
92XGG1.49
1XRH0.09
1XGT1.34

Tks
0
Comment
Question by:AXISHK
5 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40527389
Where do you want it splitting into? Into an array, or into cells?
0
 
LVL 18

Assisted Solution

by:Simon
Simon earned 150 total points
ID: 40527392
Sub SplitExample()
Dim arr() As String
Dim x As Integer
inputstring = "17DFA0.08 18DFB0.23 92XGG1.49 1XRH0.09 1XGT1.34"
arr = Split(inputstring, " ")
For x = LBound(arr) To UBound(arr)
    Debug.Print arr(x)
Next

Set wb = Workbooks.Add
With wb.Worksheets(1)
    For x = LBound(arr) To UBound(arr)
        .Cells(x + 1, 1) = arr(x)
    Next
End With

End Sub
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40527916
if you just need the data put into a cell, you might be able to use something like this:
a="17DFA0.08 18DFB0.23 92XGG1.49 1XRH0.09 1XGT1.34"
activecell.value = replace(a," ",vbcrlf)

Open in new window

0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 150 total points
ID: 40528041
Dim strParts() As String

strParts = Split(YourString, " ")

Open in new window

strParts(0) will be 17DFA0.08 and strParts(1) will be 18DFB0.23, etc.
0
 
LVL 45

Accepted Solution

by:
aikimark earned 200 total points
ID: 40528052
You can also populate the parsed/split data into multiple cells as follows:
a="17DFA0.08 18DFB0.23 92XGG1.49 1XRH0.09 1XGT1.34"
vector =  Split(a, " ")
activesheet.range(activecell,activecell.Offset(ubound(vector))).Value=worksheetfunction.transpose(vector)

Open in new window

I describe these and other techniques in my Fast Data Push to Excel article:
http:A_2253.html
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question