Link to home
Start Free TrialLog in
Avatar of azaun
azaun

asked on

VB script to split cells with carriage return into new rows

I have a spreadsheet that contains columns with multiple cells with carriage returns.  I would like to split the carriage returns into new rows across the entire spreadsheet.

I would like a vb script to pull the data apart and place it into a new tab in the same workbook.

See the below for a sample dataset and required output.

Original data set - ALL IN ONE ROW IN SPREADSHEET W CARRIAGE RETURNS:
COL1       COL2     COL3    COL4     COL5     COL6
UNRD     SVO31    A1S      UNRD                   N
MTR                        AAI       MTR       ZZ
GRP                        ATB      GRP        AA
VMA                       AAA      VMA       BB

Required data set - DATA MOVED TO MULTIPLE ROWS IN SPREADSHEET:
R1     COL1       COL2      COL3     COL4      COL5      COL6
R2     UNRD     SVO31     A1S       UNRD                    N
R3     MTR                         AAI        MTR        ZZ
R4     GRP                         ATB       GRP         AA
R5     VMA                        AAA       VMA        BB
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

So the data in each "column" is currently in a single cell? Can you post an actual workbook showing the layout?
Avatar of azaun
azaun

ASKER

Yes - the data in the original data set is in 1 row, multiple columns.  Spreadsheet below. User generated imageHaving trouble attaching actual spreadsheet.
Avatar of azaun

ASKER

Anyone have any thoughts on a possible solution?
--corp.chartercom.com-Users-MO-Home-stl-
ASKER CERTIFIED SOLUTION
Avatar of Rob Brockett
Rob Brockett
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of azaun

ASKER

Rob - that worked for what I needed.  It didn't keep each column lined up perfectly, however for my purposes that wasn't critical.

For example:
ABC                  
DEF                  123
GHI                  456

Became:
ABC                 123
DEF                  456
GHI

Thanks!!
hi Azaun,

Thank you, I'm pleased I could help.

The code worked on the data set that I created & it works when I type your last example into excel as well. Can you please attach/upload a file saved in an excel format (ie xls, xlsx, xlsm or xlsb) that shows the error?

Rob
I am trying to use the macros above can anyone help to debug the following at all?

For RowInd = LBound(InputRngArr) To UBound(InputRngArr)

Thank you in a advance!