Create multiple rows for multiple data points in the same attribute

agnes61

New Member
Joined
Feb 7, 2018
Messages
1
How can I create multiple rows when there are multiple data points for the same attribute? Thanks!!!

For example, if there are 3 investors in company ABC, then there will be 3 rows
[FONT=&quot]
-------------------------------------------------------------------------

[/FONT]
[TABLE="width: 548"]
<colgroup><col><col span="3"></colgroup><tbody>[TR]
[TD]From:[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Company[/TD]
[TD]Investor_1[/TD]
[TD]Investor_2[/TD]
[TD]Investor_3[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]X[/TD]
[TD]Y[/TD]
[TD]Z[/TD]
[/TR]
[TR]
[TD]DEF[/TD]
[TD]U[/TD]
[TD]X[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]……[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD][/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]To:[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Deal_ID[/TD]
[TD]Company[/TD]
[TD]Investors[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]ABC_X[/TD]
[TD]ABC[/TD]
[TD]X[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]ABC_Y[/TD]
[TD]ABC[/TD]
[TD]Y[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]ABC_Z[/TD]
[TD]ABC[/TD]
[TD]Z[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DEF_U[/TD]
[TD]DEF[/TD]
[TD]U[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DEF_X[/TD]
[TD]DEF[/TD]
[TD]X[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]……[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
you need a bit of vba to do this

add this code and run it

Code:
Sub trnsp()
Dim iArr As Variant, iRow As Long, iCol As Long, resVar As Variant, iCounter As Long, selectedRng As Excel.Range

On Error Resume Next
Set selectedRng = Application.InputBox("Select the region of your data", , , , , , , 8)
On Error GoTo 0

If selectedRng Is Nothing Then Exit Sub

iArr = selectedRng.Value

ReDim resVar(0 To 2, 0 To 500)
resVar(0, 0) = "Deal_ID"
resVar(1, 0) = "Company"
resVar(2, 0) = "Investors"

For iRow = LBound(iArr, 1) + 1 To UBound(iArr, 1)
    For iCol = LBound(iArr, 2) + 1 To UBound(iArr, 2)
        If Not iArr(iRow, iCol) = vbNullString Then
            iCounter = iCounter + 1
            If iCounter > UBound(resVar, 2) Then ReDim Preserve resVar(0 To 2, 0 To UBound(resVar, 2) + 500)
            resVar(0, iCounter) = iArr(iRow, 1) & "_" & iArr(iRow, iCol)
            resVar(1, iCounter) = iArr(iRow, 1)
            resVar(2, iCounter) = iArr(iRow, iCol)
        End If
    Next iCol
Next iRow
If iCounter < UBound(resVar, 2) Then ReDim Preserve resVar(0 To 2, 0 To iCounter)
Application.InputBox("Select where to export your results", , , , , , , 8).Cells(1, 1).Resize(UBound(resVar, 2) + 1, UBound(resVar, 1) + 1).Value = Application.Transpose(resVar)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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