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

hpernaf

New Member
Joined
Jul 1, 2019
Messages
5
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?



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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,324
Office Version
365
Platform
Windows
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
 

hpernaf

New Member
Joined
Jul 1, 2019
Messages
5
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,324
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,082,334
Messages
5,364,681
Members
400,810
Latest member
elbashka

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top