Disaggregating data

afndst

Board Regular
Joined
Sep 8, 2015
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Hello

Does anyone know VBA code to transform X into Y?

[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width: 48pt; text-align: right;"> </colgroup><tbody>[TR]
[TD="class: xl64, width: 64, align: right"]X[/TD]
[TD="class: xl64, width: 64, align: right"]F[/TD]
[TD="class: xl64, width: 64, align: right"]Y[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[/TR]
</tbody>[/TABLE]
Regards

António Teixeira
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this.

Code:
Sub Disaggregate()
Dim arrIn As Variant
Dim arrOut()
Dim I As Long
Dim J As Long
Dim cnt As Long

    arrIn = Range("A2:B4")
    
    ReDim arrOut(1 To Application.Sum(Application.Index(arrIn, , 2)), 1 To 1)
    
    For I = LBound(arrIn) To UBound(arrIn)
    
        For J = 1 To arrIn(I, 2)
            cnt = cnt + 1
            
            arrOut(cnt, 1) = arrIn(I, 1)
        Next J
    
    Next I
    
    Range("C2").Resize(UBound(arrOut)).Value = arrOut
    
End Sub
 
Upvote 0
Hello

It works perfectly.

Thank you very much

Try this.

Code:
Sub Disaggregate()
Dim arrIn As Variant
Dim arrOut()
Dim I As Long
Dim J As Long
Dim cnt As Long

    arrIn = Range("A2:B4")
    
    ReDim arrOut(1 To Application.Sum(Application.Index(arrIn, , 2)), 1 To 1)
    
    For I = LBound(arrIn) To UBound(arrIn)
    
        For J = 1 To arrIn(I, 2)
            cnt = cnt + 1
            
            arrOut(cnt, 1) = arrIn(I, 1)
        Next J
    
    Next I
    
    Range("C2").Resize(UBound(arrOut)).Value = arrOut
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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