Generate a set of random numbers with the specific AVERAGE

BonScie

New Member
Joined
Jul 13, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hi there, upon searching around the net I came across with Mr.Eric W.'s reply with one of the post here regarding generating random numbers with target overall total.

Link: generating a set of random numbers to total a set value

I have pretty much same problem but the target is AVERAGE of the generated random number instead of the overall total.

Your help will be much appreciated. Thank you in advance.
 

Attachments

  • GivenFigures.png
    GivenFigures.png
    5.4 KB · Views: 154
I'm glad you're satisfied.;)

Hi again, Sir! With the VB code you made you put the specific needed values. I was thinking of a way on how can I refer it in a cell. Tried doing this but I guess it is not how it works ?. Kindly help me please... Thank you in advance!

vMin = 8.45 vMin = F2
vAverage = 11.55 vAverage = D2
vMax = 15.55 vMax = E2
vNumbers = 4 vNumbers = C2

Average_RNG.xlsm
ABCDEFG
112.78Base(n)AverageMaxMin
29.194.0011.5515.558.45
313.02
411.21
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Jan_case1
Cell Formulas
RangeFormula
C2C2=COUNTIF(A1:A493,">0")
Named Ranges
NameRefers ToCells
Print_Area=Jan_case1!$A$1:$G$153C2
Print_Titles=Jan_case1!$1:$7C2
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
No, you did nothing wrong, it's just a weakness of the algorithm I used. The way it works is it selects the first number in the accepted range. The next number it selects is more constrained since the total is fixed. I handle this by adjusting the acceptable upper and lower bounds for that number. After enough numbers, those acceptable bounds get closer and closer, until they converge on either the high or low bound. I don't know a good way to handle that with formulas only. I can think of a few ways using VBA, but it seems that EXCEL MAX has provided a workable macro already. Let me know if you want another option.

EXCEL MAX macro works great for me I just need something to make it easy to use. But thanks for the offer Sir. ?
 
Upvote 0
I'm glad you're satisfied.;)

Hi, Sir, I just want to share this. I made it work, I'm so happy ?
Thank you very much!

1626596273005.png


Average_RNG.xlsm
ABCDEFG
15.72NumberAverageMaxMin
25.9346.2513.255.00
36.54
46.81
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Sheet1
 
Upvote 0
Just change this part in the code...
vMin = 8.45
vAverage = 11.55
vMax = 15.55
vNumbers = 298

with this...
vMin = Sheets("Jan_case1").[F2]
vAverage = Sheets("Jan_case1").[D2]
vMax = Sheets("Jan_case1").[E2]
vNumbers = Sheets("Jan_case1").[C2]

Congratulations....;)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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