Splitting Multiline Cells into Separate Rows

kcjt2009

New Member
Joined
Feb 13, 2014
Messages
12
Hello Everyone,

I am having a heck of a time trying to figure out how to solve this problem of mine. I found a couple of similar questions asked, but there weren't any applicable answers.

I basically have a five column spreadsheet containing address information. While most cells only contain one piece of information, I have quite a few cells that have multiple lines of data in them because the individual has more than one address.

Here is an example. Note that Rows 1-2 contain single address info for each individual person. However, row 3 contains an individual with 3 pieces of address information in the four right hand columns:

Row 1: Unique ID | Name | Street Address | City | State | Zip Code
Row 2: Unique ID | Name | Street Address | City | State | Zip Code
Row 3: Unique ID | Name | Street Address | City | State | Zip Code

[carriage return in street address, city, state and zip cells]

--------------------------------- |Street Address | City | State | Zip Code

[carriage return in street address, city, state and zip cells]

--------------------------------- |Street Address | City | State | Zip Code

Row 4: Unique ID | Name | Street Address | City | State | Zip Code
Row 5: Unique ID | Name | Street Address | City | State | Zip Code


Please note that some individuals have 2-4 different addresses.

I would like to manipulate the 5 rows of example data above so that when I am done I have the following:

1. 7 rows of data (5 individuals with 7 total addresses)
2. Automatically copy and paste the unique id number and name into the two new rows that were created so that I have the following:

Row 1: Unique ID - 001 | Joe Chang | Street Address | City | State | Zip Code
Row 2: Unique ID - 002 | Joey Chung | Street Address | City | State | Zip Code
Row 3: Unique ID - 003 | John Smith | Street Address | City | State | Zip Code
Row 4: Unique ID - 003 | John Smith | Street Address | City | State | Zip Code
Row 5: Unique ID - 003 | John Smith | Street Address | City | State | Zip Code

Row 6: Unique ID - 004 | Jane Derry | Street Address | City | State | Zip Code
Row 7: Unique ID - 005 | Julie March | Street Address | City | State | Zip Code

Your help is kindly appreciated. Thank you.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
kcjt2009,

Welcome to the MrExcel forum.

What version of Excel and Windows are you using?


We would like to see some actual raw data.

So that we can get it right the first time:

Can you post a screenshot of the actual raw data worksheet?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker

Or, when using Internet Explorer, just put borders around your data in Excel and copy those cells into your post.
See reply #2 the BLUE text in the following link:
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
I am using the 2013 Office Suite and Windows 8.

Below you will see a small sample with the header row and five additional rows of data. I am trying to change rows that look like the yellow one that I have highlighted. They can have anywhere from 2-4 addresses in a single row.

I am trying to extract the information to create rows below it while pushing the other text down without deleting it.



Excel 2012
ABCDEF
1IDNameStreetCityZipState
24444FLOWERS,LEONARD141 89TH AVE APT # D
OAKLAND94621CA
35555FLUKER,FREDRICK LEWIS721 HILLSIDE STOAKLAND94605CA
46666DAVIS,JONATHAN3725 MORTENSEN RD


2400 LECONTE AVE
SAN LEANDRO


BERKELEY
94578




94705
CA




CA
57777FRANCO,BALTAZAR17009 MONTROSE AVESAN LORENZO94580CA
68888FRANKLIN,CURTIS EUGENE6234 15TH ST APT # 610
OAKLAND94612CA
7
8
9
104444FLOWERS,LEONARD141 89TH AVE APT # D
OAKLAND94621CA
115555FLUKER,FREDRICK LEWIS721 HILLSIDE STOAKLAND94605CA
126666DAVIS,JONATHAN3725 MORTENSEN RD
SAN LEANDRO
94578
CA
136666DAVIS,JONATHAN2400 LECONTE AVEBERKELEY94705CA
147777FRANCO,BALTAZAR17009 MONTROSE AVESAN LORENZO94580CA
158888FRANKLIN,CURTIS EUGENE6234 15TH ST APT # 610
OAKLAND94612CA

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3

Worksheet Formulas
CellFormula
A1ID
B1Name
C1Street
D1City
E1Zip
F1State
A24444
B2FLOWERS,LEONARD
C2141 89TH AVE APT # D
D2OAKLAND
E294621
F2CA
A35555
B3FLUKER,FREDRICK LEWIS
C3721 HILLSIDE ST
D3OAKLAND
E394605
F3CA
A46666
B4DAVIS,JONATHAN
C43725 MORTENSEN RD


2400 LECONTE AVE
D4SAN LEANDRO


BERKELEY
E494578




94705
F4CA




CA
A57777
B5FRANCO,BALTAZAR
C517009 MONTROSE AVE
D5SAN LORENZO
E594580
F5CA
A68888
B6FRANKLIN,CURTIS EUGENE
C66234 15TH ST APT # 610
D6OAKLAND
E694612
F6CA
A7
B7
C7
D7
E7
F7
A8
B8
C8
D8
E8
F8
A9
B9
C9
D9
E9
F9
A104444
B10FLOWERS,LEONARD
C10141 89TH AVE APT # D
D10OAKLAND
E1094621
F10CA
A115555
B11FLUKER,FREDRICK LEWIS
C11721 HILLSIDE ST
D11OAKLAND
E1194605
F11CA
A126666
B12DAVIS,JONATHAN
C123725 MORTENSEN RD
D12SAN LEANDRO
E1294578
F12CA
A136666
B13DAVIS,JONATHAN
C132400 LECONTE AVE
D13BERKELEY
E1394705
F13CA
A147777
B14FRANCO,BALTAZAR
C1417009 MONTROSE AVE
D14SAN LORENZO
E1494580
F14CA
A158888
B15FRANKLIN,CURTIS EUGENE
C156234 15TH ST APT # 610
D15OAKLAND
E1594612
F15CA

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
kcjt2009,

Sample raw data:


Excel 2007
ABCDEF
1IDNameStreetCityZipState
24444FLOWERS,LEONARD141 89TH AVE APT # DOAKLAND94621CA
35555FLUKER,FREDRICK LEWIS721 HILLSIDE STOAKLAND94605CA
46666DAVIS,JONATHAN3725 MORTENSEN RD 2400 LECONTE AVESAN LEANDRO BERKELEY94578 94705CA CA
57777FRANCO,BALTAZAR17009 MONTROSE AVESAN LORENZO94580CA
68888FRANKLIN,CURTIS EUGENE6234 15TH ST APT # 610OAKLAND94612CA
7
8
Sheet3


After the macro:


Excel 2007
ABCDEF
1IDNameStreetCityZipState
24444FLOWERS,LEONARD141 89TH AVE APT # DOAKLAND94621CA
35555FLUKER,FREDRICK LEWIS721 HILLSIDE STOAKLAND94605CA
46666DAVIS,JONATHAN3725 MORTENSEN RDSAN LEANDRO94578CA
56666DAVIS,JONATHAN2400 LECONTE AVEBERKELEY94705CA
67777FRANCO,BALTAZAR17009 MONTROSE AVESAN LORENZO94580CA
78888FRANKLIN,CURTIS EUGENE6234 15TH ST APT # 610OAKLAND94612CA
8
Sheet3


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub ReorgData()
' hiker95, 02/14/2014, ME757628
Dim r As Long, lr As Long, s, i As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 3).End(xlUp).Row
For r = lr To 2 Step -1
  If InStr(Cells(r, 3), vbLf) Then
    s = Split(Cells(r, 3), vbLf)
    Rows(r + 1).Resize(UBound(s)).Insert
    Cells(r + 1, 1).Resize(UBound(s), 2).Value = Cells(r, 1).Resize(, 2).Value
    Cells(r, 3).Resize(UBound(s) + 1).Value = Application.Transpose(s)
    s = Split(Cells(r, 4), vbLf)
    Cells(r, 4).Resize(UBound(s) + 1).Value = Application.Transpose(s)
     s = Split(Cells(r, 5), vbLf)
    Cells(r, 5).Resize(UBound(s) + 1).Value = Application.Transpose(s)
    s = Split(Cells(r, 6), vbLf)
    Cells(r, 6).Resize(UBound(s) + 1).Value = Application.Transpose(s)
  End If
Next r
Range("A2:A" & lr).Rows.AutoFit
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReorgData macro.
 
Upvote 0
Hiker

Thank you so much for taking the time to help me out with this. On the practice data, it worked great. It actually created a new row for each line of data including the carriage return in the cells, which I kind of prefer.

Now, when I take it to my actual data set, I am getting a Type 13 error and cannot figure out why. When I open the debugger it points to this line and highlights it in yellow;

Cells(r, 4).Resize(UBound(s) + 1).Value = Application.Transpose(s)


After I look at the highlighted line and close the debugger, I notice that the macro changed some of the rows of data the way it is supposed to...but it only changed about 200 rows of data out of around 3400 records. And interestingly enough, nearly all the records it changed were towards the end of the sheet (last names beginning with "w". Although there were a couple of strays and it did not change all the names starting with a "w".

I have tried a smaller data set from the same list and sometimes it works just fine without issue and sometimes it presents the Type 13 error but still manages to complete some of the row splits.

Not sure how to go about providing you with the info to help me fix this.
 
Upvote 0
kcjt2009,

It is always best to display your actual raw data worksheet(s), and, the results that you are looking for. This way we can usually find a solution on the first go.

If your actual raw is very different from your original screenshot(s), then, I would prefer the following:

You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
My apologies. Here is the link:

https://app.box.com/s/t1uisiembiryq6o8taby

I originally deleted the "Show On Map" text in the address cells, but left it in since the code you provided above basically put it on its own row and i could simply delete those later.

I am thinking that perhaps some rows have more than 4 lines of data in each cell, but I don't know how to read your code and wasn't sure how to tweak it to make it account for say a cell with 12 lines of text. And I am not even sure that that is the issue.

Thank you!
 
Upvote 0
kcjt2009,

Can I have another workbook, with the raw data in worksheet Sheet1, and, in worksheet Results, what the results should be for raw data rows 2, 17, 32, 45, 90 (raw data for these rows are shown below):


Excel 2007
ABCDEF
1IDNameAddressCityZipCodeCounty
2javascript: OpenDetail('18611314B2241') Row 2AARON,JEFFREY DALE25494 JASPER RD Show On MapBARSTOWSAN BERNARDINO
17javascript: OpenDetail('38210041N4620') Row 17ADELMAN,GARY JOELPO BOX 464 Show On Map 553 W VICTORIA CT Show On MapSKYFOREST LAKE ARROWHEAD92385 92352SAN BERNARDINO SAN BERNARDINO
32javascript: OpenDetail('18600227E3520') Row 32AGUIRRE,RAFAEL15814 MIRASOL CT POB 168 15814 MIRASOL CT Show On MapHELENDALE HELENDALE92342 92342SAN BERNARDINO SAN BERNARDINO
46javascript: OpenDetail('18602239G7839') Row 46ALDANA,VICTOR DAVID7149 N BARTON STREET Show On MapSpecific address not subject to disclosureSAN BERNARDINO92404SAN BERNARDINO
90javascript: OpenDetail('43611333B2584') Row 90ANDERSON,JERRY JR7054 JUNIPER AVE Show On Map 8783 SAN VINCENTE DR Show On MapTWENTYNINE PALMS YUCCA VALLEY92277 92284SAN BERNARDINO SAN BERNARDINO
Sheet1
 
Upvote 0
kcjt2009,

The structure of your actual raw data is nothing like what your original screenshot depicted.

I have not been able to come up with a macro that will give you the results you are looking for.

Click on the Reply to Thread button, and just put the word BUMP in the thread. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0

Forum statistics

Threads
1,221,469
Messages
6,160,027
Members
451,611
Latest member
PattiButche

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top