Solved

Excel, parse strings into columns  from a list of offsets (columns widths) and column names

Posted on 2013-01-30
366 Views
How to parse strings into columns  from a list of offsets (columns widths) and column names.  The rows of text are limited to a hundred or so.  The source string length is <1000 characters,   there are about 40 columns of vary widths.
EE-Excel-parse.xls
0
Question by:AndyPandy
[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

LVL 39

Assisted Solution

nutsch earned 200 total points
ID: 38837596
On sheet 3, first row, formula starting in A1, copy across

=INDEX(Sheet2!\$B\$1:\$B\$40,COLUMN()+1)

On sheet3, second row, formula starting in A2, copy across and down:
=MID(INDEX(Sheet1!\$A:\$A,ROW()-1),INDEX(Sheet2!\$A:\$A,MATCH(A\$1,Sheet2!\$B:\$B,0)),INDEX(Sheet2!\$A:\$A,1+MATCH(A\$1,Sheet2!\$B:\$B,0))-INDEX(Sheet2!\$A:\$A,MATCH(A\$1,Sheet2!\$B:\$B,0)))

Thomas
0

LVL 92

Assisted Solution

Patrick Matthews earned 50 total points
ID: 38837621
I came up with this while Thomas was posting.  Not the most elegant thing, but it does appear to preempt errors if the source strings are not long enough.

The operative formula goes in Sheet3!A2, and is copied across and down:

=MID(Sheet1!\$A2,INDEX(Sheet2!\$A:\$A,MATCH(A\$1,Sheet2!\$B:\$B,0),1),MAX(0,IFERROR(INDEX(Sheet2!\$A:\$A,MATCH(B\$1,Sheet2!\$B:\$B,0),1),LEN(Sheet1!\$A2)+1)-INDEX(Sheet2!\$A:\$A,MATCH(A\$1,Sheet2!\$B:\$B,0),1)))

Q-28014774.xlsx
0

LVL 50

Accepted Solution

barry houdini earned 250 total points
ID: 38837711
This formula should also work for Sheet3 A2 copied across and down

=MID(LEFT(Sheet1!\$A2,MOD(INDEX(Sheet2!\$A:\$A,MATCH(A\$1,Sheet2!\$B:\$B,0)+1)-1,1000)),SUMIF(Sheet2!\$B:\$B,A\$1,Sheet2!\$A:\$A),1000)

regards, barry
0

Author Closing Comment

ID: 38837990
Thanks, you guys are genius'sssss
Thomas, nice but leaves #value when string too short.
Matt,  #Name?,  perhaps my Excel 2003 doesn't support your solution?
Barry, Nice short and sweet and no error.  Still trying to figure out how it does this.
Thanks guys!
0

LVL 92

Expert Comment

ID: 38838004
AndyPandy,

Glad to help, and not surprised that once again barry wins the formula derby :)

One of the functions I used, IFERROR, debuted in Excel 2007, so yes, in Excel 2003 and earlier you will get a #NAME error if you use it.

Patrick
0

Featured Post

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Suggested Courses
Course of the Month7 days, 22 hours left to enroll