RANDBETWEEN Two decimal numbers to produced a decimal number

Taconumber

New Member
Joined
Dec 5, 2021
Messages
4
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Howdy,

I am stuck on a formula and am hoping someone here can help me.

Essentially, i am doing a tolerance sheet. Showing the design value, the actual value and the difference between the two. There is a tolerance of +0.015 and -0.000. So if the difference falls out of this range i need it to randomly generate a number that is between the design value and the design tolerance.

I have come up with this. =IF(C7>$B$2,RANDBETWEEN(A7-$B$3,A7+$B$2) BUT it only generates a integer..

and if i use the formula =IF(C7>$B$2,RANDBETWEEN(A7-$B$3,A7+$B$2)+RAND()) It generates a value that is out of the tolerance range because it generates the RANDBETWEEN and adds the RAND whch returns a decimal.

I have attached a example work book.

tolerance workbook.xlsx
ABCDEFGHI
1
2Upper Tolerance0.015
3Lower Tolerance0.000
4
5DIFF
6456.983457.0170.034457.000FALSE456.998
7456.897456.883-0.014FALSE457.993
8456.955456.942-0.013FALSE457.054
9456.888456.9230.035457.722FALSE
Sheet1
Cell Formulas
RangeFormula
F6F6=IF(C6>$B$2,RANDBETWEEN(A6,I6))
G6:G9G6=IF(C6<$B$3,RANDBETWEEN(A7-$B$3,A7+$B$2)+RAND())
F7:F9F7=IF(C7>$B$2,RANDBETWEEN(A7-$B$3,A7+$B$2)+RAND())
I6I6=A6+$B$2
C6:C9C6=B6-A6
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this:
varios 18oct2022.xlsm
ABCDEF
1
2Upper Tolerance0.015
3Lower Tolerance0
4
5DIFF
6456.983457.0170.034456.996
7456.897456.883-0.014FALSO
8456.955456.942-0.013FALSO
9456.888456.9230.035456.893
Hoja2
Cell Formulas
RangeFormula
C6:C9C6=B6-A6
F6:F9F6=IF(C6>$B$2,(RANDBETWEEN(A6*1000,(A6+$B$2)*1000))/1000)


I hope with that example you can get the value in case the difference is less than 0. Otherwise explain what you need when the difference is less than 0.
 
Upvote 0
Try to multiply both with 1000 to get random integer first, then afterall divide back to 1000

=IF(C6>$B$2,RANDBETWEEN((A6-$B$3)*1000,(A6+$B$2)*1000)/1000)
 
Upvote 0
They both work great! I was trying to think logically but it appears you need some creativity with this formula.
Try to multiply both with 1000 to get random integer first, then afterall divide back to 1000

=IF(C6>$B$2,RANDBETWEEN((A6-$B$3)*1000,(A6+$B$2)*1000)/1000)
Try this:
varios 18oct2022.xlsm
ABCDEF
1
2Upper Tolerance0.015
3Lower Tolerance0
4
5DIFF
6456.983457.0170.034456.996
7456.897456.883-0.014FALSO
8456.955456.942-0.013FALSO
9456.888456.9230.035456.893
Hoja2
Cell Formulas
RangeFormula
C6:C9C6=B6-A6
F6:F9F6=IF(C6>$B$2,(RANDBETWEEN(A6*1000,(A6+$B$2)*1000))/1000)


I hope with that example you can get the value in case the difference is less than 0. Otherwise explain what you need when the difference is less than 0.


They both work great! I was trying to think logically but it appears you need some creativity with this formula.

Thanks for the help. It is much appreciated.
 
Upvote 0
Just to build on what others have posted, the randbetween function will only return an integer.

There is another function "=rand()" that will return decimals to however plant places you have the cell formatted to. You can also round the function to 3 places if you wanted to fix it.

So another way to complete the task is to use the rand() function to add a random decimal.

The syntax to build this function out further is =rand()*lower*upper.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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