Split two columns into separate rows, without losing common identifiers

tRiglyc

New Member
Joined
Mar 21, 2013
Messages
8
Hello,

I have a spreadsheet with about 2500 rows that contains contact e-mails for companies. To give you a rough example, it's formatted kind of like this:

Excel 2007
CompanyStateEmailEmailEmail
ABC CompanyOHemail1@abc.comemail2@abc.comemail3@abc.com
XYZ CompanyNYemail1@XYZ.comemail2@XYZ.comemail3@XYZ.com

<tbody>
</tbody>

I need to put each e-mail address on its own row, without losing the company info that goes with it. So I'd like it to look like this.

Excel 2007
CompanyStateEmail
ABC CompanyOHemail1@abc.com
ABC CompanyOHemail2@abc.com
ABC CompanyOHemail3@abc.com
XYZ CompanyNYemail1@XYZ.com
XYZ CompanyNYemail2@XYZ.com
XYZ CompanyNYemail3@XYZ.com

<tbody>
</tbody>

I'm guessing I'll need a macro to do this, but I can't find anything for this exact scenario. (I'm also a complete rookie with macros.) Any help will be greatly appreciated.

Thanks!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Welcome to MrExcel.

Try:

Code:
Sub Test()
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim ShNew As Worksheet
    Dim x As Integer
    Dim r As Integer
    Dim c As Integer
    Set Sh = Worksheets("Sheet1")
    Set Rng = Sh.Range("A1").CurrentRegion
    Set ShNew = Worksheets.Add
    x = 1
    With ShNew
        .Cells(x, 1) = Sh.Cells(x, 1)
        .Cells(x, 2) = Sh.Cells(x, 2)
        .Cells(x, 3) = "Email"
    End With
    x = x + 1
    For r = 2 To Rng.Rows.Count
        For c = 3 To Rng.Columns.Count
            ShNew.Cells(x, 1) = Rng.Cells(r, 1)
            ShNew.Cells(x, 2) = Rng.Cells(r, 2)
            ShNew.Cells(x, 3) = Rng.Cells(r, c)
            x = x + 1
        Next c
    Next r
End Sub
 
Upvote 0
That's phenomenal - worked perfectly! Can't even imagine how long it would have taken me to figure that out on my own.

Thanks a lot, Andrew!
 
Upvote 0

Forum statistics

Threads
1,203,174
Messages
6,053,918
Members
444,694
Latest member
JacquiDaly

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