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]
From:
CompanyInvestor_1Investor_2Investor_3
ABCXYZ
DEFUX
……
To:
Deal_IDCompanyInvestors
ABC_XABCX
ABC_YABCY
ABC_ZABCZ
DEF_UDEFU
DEF_XDEFX
……

<colgroup><col><col span="3"></colgroup><tbody>
</tbody>
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,215,824
Messages
6,127,087
Members
449,358
Latest member
Snowinx

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