parsing data with no set delimiter or fixed length.

O

ORLANDO V

Any ideas on how to do a text to columns on sample data below? The only
thing somewhat static is the fact that each row has seven numbers starting
from the right working left. (where "---" equals blank or zero.)
I appreciate any help given?

iShares S&P 500 Index IVV (6.27) (10.86) (6.27) (2.70) 7.07 11.78 ---
iShares S&P Global 100 Index IOO (8.68) (12.15) (8.68) 0.51 9.03 13.47 ---
iShares MSCI EAFE Index EFA (7.85) (13.82) (7.85) (0.05) 13.78 20.22 ---
iShares Lehman Aggregate Bond AGG 2.31 4.15 2.31 9.59 4.88 --- ---
 
P

Pete_UK

Do you actually get "---" in the data?

It looks as if for every "proper" number you have a decimal point.
What happens if one of the numbers is an integer? Do you get 4.00 or
4 ?

How many different text items do you get? If you only have a limited
number (as I suspect), then you could set up a table like this:

iShares S&P 500 Index IVV ABC
iShares S&P Global 100 Index IOO ABD
iShares MSCI EAFE Index EFA ABE
iShares Lehman Aggregate Bond AGG ABF
and so on ...

and then you could use Find & Replace within a macro (or SUBSTITUTE in
a formula) to change your text values to some three letter code plus a
space, and then do Data | Text-to-columns on what remains, using
<space> as the delimiter.

Then you could convert the 3-letter codes back to text again using
INDEX/MATCH.

Hope this helps.

Pete
 
R

Ron Rosenfeld

Any ideas on how to do a text to columns on sample data below? The only
thing somewhat static is the fact that each row has seven numbers starting
from the right working left. (where "---" equals blank or zero.)
I appreciate any help given?

iShares S&P 500 Index IVV (6.27) (10.86) (6.27) (2.70) 7.07 11.78 ---
iShares S&P Global 100 Index IOO (8.68) (12.15) (8.68) 0.51 9.03 13.47 ---
iShares MSCI EAFE Index EFA (7.85) (13.82) (7.85) (0.05) 13.78 20.22 ---
iShares Lehman Aggregate Bond AGG 2.31 4.15 2.31 9.59 4.88 --- ---

See if this macro does what you want. It may need some tweaking, as well as a
test to make sure all the components are present.

Since you did not indicate how you wanted to parse the text portion, nor what
things would look like if there is a "blank", I made some assumptions which may
be incorrect.

Place the code below into a regular module. Select the data to be parsed, and
execute the macro.


===================
Option Explicit
Sub ParseSpecial()
Dim c As Range
Dim vData As Variant
Dim lStartNums As Long
Dim i As Long
Dim sTemp As String

For Each c In Selection
sTemp = ""
vData = Split(c.Value)
lStartNums = UBound(vData) - 6
Range(c(1, 2), c(1, 11)).ClearContents
c(1, 2).Value = vData(0)
For i = 1 To UBound(vData) - 8
sTemp = sTemp & " " & vData(i)
Next i
c(1, 3).Value = Trim(sTemp)
c(1, 4).Value = vData(i)
For i = UBound(vData) - 6 To UBound(vData)
c(1, 5 + i - UBound(vData) + 6).Value = vData(i)
Next i
Next c
End Sub
============================
--ron
 
O

ORLANDO V

The three dashes appear in the data but not the quotes.
For integers, I would get 4.00
There are several hundreds different text items.

I think what you are suggesting is to change the text items to something
that will be uniform and easy to parse, then after the parse, change it back
to what it originally was ? That is really thinking outside the box!
Thanks, I'll try it.
I guess once I get the table set up it should be okay going forward since
the text items rarely change.

Let me know if you have any other ideas on this.
Thanks again.
 
O

ORLANDO V

The three dashes appear in the data but not the quotes.
For integers, I would get 4.00
There are several hundreds different text items.

I think what you are suggesting is to change the text items to something
that will be uniform and easy to parse, then after the parse, change it back
to what it originally was ? That is really thinking outside the box!
Thanks, I'll try it.
I guess once I get the table set up it should be okay going forward since
the text items rarely change.

Let me know if you have any other ideas on this.
Thanks again.
 
P

Pete_UK

Glad to be of help, and of prompting some ideas.

Let us know how you get on.

Pete
 
O

ORLANDO V

Thank you for all the footwork. I will definitely try this.
(I appreciate the turnkey solution.)
 
O

ORLANDO V

Thank you for all the footwork. I will definitely try this.
(I appreciate the turnkey solution.)
 
R

Ron Rosenfeld

Thank you for all the footwork. I will definitely try this.
(I appreciate the turnkey solution.)

You're welcome. Let me know how it works out. It may need some tweaking if any
of my assumptions were incorrect.
--ron
 
R

Ron Rosenfeld

You're welcome. Let me know how it works out. It may need some tweaking if any
of my assumptions were incorrect.
--ron

In particular, if this data came from the internet, it may be necessary to
strip out some extraneous, non-printing characters.
--ron
 
O

ORLANDO V

I tried it today and it worked extremely well. No tweaking necessary!
Thank you very much indeed.
 
O

ORLANDO V

I tried it today and it worked extremely well. No tweaking necessary!
Thank you very much indeed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top