Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.
Become a Premium Member and unlock a new, free course in leading technologies each month.
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Option Explicit
Sub Randomish()
Dim xMin As Double
Dim xActual As Double
Dim xTarget As Double
Dim i As Long
Sheets("Sheet2").Activate
xTarget = Range("B1")
xMin = 100000000
Application.ScreenUpdating = False
For i = 1 To 100
Range("B6:F105").Formula = "=(RANDBETWEEN($B$3,$B$4)+(RANDBETWEEN(0,9)/100))"
Range("B6:F105").Copy
Range("B6:F105").PasteSpecial xlPasteValues
xActual = Range("H1")
If Abs(xTarget - xActual) / xTarget < 0.01 Then
MsgBox ("Run complete - difference is " & Format(Abs(xTarget - xActual) / xTarget, "0.00%"))
Exit Sub
End If
If Abs(xTarget - xActual) < xMin Then xMin = Abs(xTarget - xActual)
Next
MsgBox ("Sorry - couldn't get within reach. Closest was " & Format(xMin / xTarget, "0.00%") & ". Please try again.")
Application.ScreenUpdating = True
End Sub
Regards,If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.