Draw random numbers from 1 to 20 million and save results from the draw

hpernaf

New Member
Joined
Jul 1, 2019
Messages
27
Hi everyone!


Could anyone tell me how it is possible to sort random numbers (without repetition) between a range of 1 to 20 million?
Basically I need to enter the drawn range into two cells (minimum value and maximum value) and display the number generated in another cell.


Would there also be the option to save a record with the numbers that were generated with the date and time?

Capturar.png


I've been looking for solutions on the internet and I have not found anything that has answered me so far. I was only able to generate numbers in an active cell using the code below. But that does not answer me.



Sub generate_numbers()
Randomize
ActiveCell.Value = CInt(Int((200000000 * Rnd()) + 1))
End Sub


If anyone can help me, I'm leaving the worksheet attached.
https://drive.google.com/file/d/1hVidzxBQhfvRDHHcg5PBGMkJrXHlq9OE/view?usp=sharing


Thank you
 

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
How about
Code:
Sub hpneaf()
   Dim Low As Double
   Dim High As Double
   Dim Res As Double
   
   Randomize
   Low = Range("D5").Value
   High = Range("F5").Value
   Res = Int((High - Low + 1) * Rnd() + Low)
   Range("E7").Value = Res
   With Range("I" & Rows.Count).End(xlUp)
      .Offset(1).Value = Res
      .Offset(1, 1).Value = Date
      .Offset(1, 2).Value = Time
   End With
End Sub
 
Upvote 0
How about
Code:
Sub hpneaf()
   Dim Low As Double
   Dim High As Double
   Dim Res As Double
   
   Randomize
   Low = Range("D5").Value
   High = Range("F5").Value
   Res = Int((High - Low + 1) * Rnd() + Low)
   Range("E7").Value = Res
   With Range("I" & Rows.Count).End(xlUp)
      .Offset(1).Value = Res
      .Offset(1, 1).Value = Date
      .Offset(1, 2).Value = Time
   End With
End Sub

Perfect!
Thank you very much.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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