?
Solved

Split String to Array

Posted on 2015-01-02
5
Medium Priority
?
197 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 600 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 46

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 49

Assisted Solution

by:Martin Liss
Martin Liss earned 600 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 46

Accepted Solution

by:
aikimark earned 800 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

801 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