Solved

Split String to Array

Posted on 2015-01-02
5
173 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:SimonAdept
SimonAdept 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 45

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now