Fill in values on in a column base on percentages of that value in another column

sparkzilla

New Member
Joined
Apr 9, 2019
Messages
3
Hi, I would like to fill values into a column based on the percentages of that value in another column. For example, if the first value is 10 and it has 5% of the total, then if the total number of rows is 100, then the first five will be filled in with the value 10. In the example below I assume that the result column is 100 rows deep, however the script/formula should be able to create proportional results for any number of rows. For example, if the total number of rows is 300, then we would get 15 rows of he first value (10). Thank you for your help.


Book1
ABCD
3ValuePercentageResult
4105%10
5207%10
63020%10
74055%10
85013%10
9100%20
1020
1120
1220
1320
1420
1520
1630
1730
1830
19and so on
Sheet1
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi sparkzilla,

Welcome to the MrExcel Forum:

I have a question... If the total number of rows is 300 as you suggest. How do we know that from looking at your data?
 
Upvote 0
Hi sparkzilla,

Welcome to the MrExcel Forum:

I have a question... If the total number of rows is 300 as you suggest. How do we know that from looking at your data?

Thanks! Feel free to add the number of rows as a value in another cell.
 
Upvote 0
With your header row as you show it on Row 3, I used Cell C3 for your number of rows. See if this is what you want...

Code:
Sub test()


    Dim ct As Long, rws As Long, lRow As Long, i As Long, nr As Long, fr As Range
    
    lRow = Cells(Rows.Count, 1).End(xlUp).Row
    ct = Range("C3")
    Set fr = Range("D4")
    For i = 4 To lRow
        rws = Application.WorksheetFunction.RoundUp(Cells(i, 2).Value * ct, 0)
        fr.Resize(rws) = Cells(i, 1).Value
        nr = Cells(Rows.Count, 4).End(xlUp).Row + 1
        Set fr = Range("D" & nr)
    Next
    
End Sub
 
Upvote 0
This is great. It works perfectly. Thank you! If I had multiple value and percentage rows on one sheet, how would I show the results on another sheet in the same worksheet?
 
Upvote 0
I am glad that this works for you. The only caveat, is that due to rounding, you may get more or less than the number of rows deep that is inputted.

Could you be a drop more explicit on what your new request is. I am not sure I follow what is where and where you want the output.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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