Random Date and Time

Bill Jones

New Member
Joined
Apr 30, 2019
Messages
1
I am trying to generate a random Date and Time in excel but I need to remove the
volatility out of the Randbetween function. The formula I an currently using is as follows:

=RANDBETWEEN(--"2019-03-17",--"2019-04-29")+RAND()*("0:59"-"17:00")+"1:00"

But by using this function the generated Date and Time in volatile and I need it to stay constant once the Date and Time are generated of that cell.

I am not good an programming Macro's so I have not gone that route but I assume that is the only way to accomplish this task.

If anyone can help it would be appreciated.<strike></strike>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
If you do not want to use VBA you would need to copy it and past as values to remove the formula and only leave the value.
 
Upvote 0
If you are OK with VBA this should work

Code:
Sub randdateandtime()
r = Int((DateValue("4 / 29 / 19") - DateValue("3 / 17 / 19") + 1) * Rnd + DateValue("3 / 17 / 19")) + Rnd * (TimeValue("0:59") - TimeValue("17:00")) + TimeValue("1:00")
Range("A7") = r
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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