Solved

Split String to Array

Posted on 2015-01-02
5
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 47

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

688 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