Convert a single row to multiple rows with the same first column value

mansaf

New Member
Joined
Oct 2, 2017
Messages
4
Hi,

I saw a couple of threads with similar requests but not quite what i need.

https://www.mrexcel.com/forum/excel...row-multiple-rows-same-column-value-help.html
https://www.mrexcel.com/forum/excel...ngle-row-multiple-rows-same-column-value.html

I need to convert rows from this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]ID 1[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]11[/TD]
[TD]12[/TD]
[TD]13[/TD]
[TD]14[/TD]
[TD]15[/TD]
[TD]16[/TD]
[TD]17[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]ID 2[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ID 3[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]11[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


To this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]ID 1[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]11[/TD]
[TD]12[/TD]
[TD]13[/TD]
[TD]14[/TD]
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
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]ID 2[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
etc...

The data in each row does not end in the same column, however it will not pass column "S".

i currently have over 4000 rows and will be adding more to it.

Using Excel 2016
 

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.
Code:
Public Sub mansaf()

Dim lastRow As Long
Dim thisRow As Long
Dim lastCol As Long
Dim thisCol As Long
Dim nextRow As Long

Range("U:V").ClearContents
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
nextRow = 1
For thisRow = 1 To lastRow
    lastCol = Cells(thisRow, "T").End(xlToLeft).Column
    For thisCol = 2 To lastCol
        Cells(nextRow, "U").Value = Cells(thisRow, 1).Value
        Cells(nextRow, "V").Value = Cells(thisRow, thisCol).Value
        nextRow = nextRow + 1
    Next thisCol
Next thisRow

End Sub

WBD
 
Upvote 0
Thank you very much. Is there anyway to skip the blank rows generated from the empty cells?
 
Upvote 0
Code:
Public Sub mansaf()

Dim lastRow As Long
Dim thisRow As Long
Dim lastCol As Long
Dim thisCol As Long
Dim nextRow As Long

Range("U:V").ClearContents
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
nextRow = 1
For thisRow = 1 To lastRow
    lastCol = Cells(thisRow, "T").End(xlToLeft).Column
    For thisCol = 2 To lastCol
        If Trim$(Cells(thisRow, thisCol).Value) <> "" Then
            Cells(nextRow, "U").Value = Cells(thisRow, 1).Value
            Cells(nextRow, "V").Value = Cells(thisRow, thisCol).Value
            nextRow = nextRow + 1
        End If
    Next thisCol
Next thisRow

End Sub

WBD
 
Upvote 0
unfortunately its giving me the same results exactly as the first code.

Thank you.
 
Last edited by a moderator:
Upvote 0
OK, we have a few issues going on with your posts.

First, please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to your original thread. Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules). I have removed the same question that you posted on to old existing threads.

It is usually best to start your own thread, so it appears as a new unanswered question. Wherever you post, only post the question in one place.

Second, it looks like you are using the Google "Poper Blocker". This causes a bunch of wacky code to be added to the end of some of your posts. If you are going to use this blocker, you will need to add mrexcel.com to the whitelist. Otherwise, most of your posts may go to a Moderated status (which means they will not show up on the forum until a Moderator corrects it). See here for instructions: [/COLOR]https://www.mrexcel.com/forum/about-board/1024515-weird-posting-issue.html#post4919212


 
Last edited:
Upvote 0
unfortunately its giving me the same results exactly as the first code.

Thank you.

You're not giving many clues here. Sample data, sample output and proper description of the problem would help. Where are the blank cells?

WBD
 
Upvote 0
my apologies, i found the issue, a mistake from my end. Thank you for all your help!
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,111
Messages
6,170,160
Members
452,305
Latest member
chenhi131

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