vba 如何在 Excel 中生成随机时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18195529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:24:00  来源:igfitidea点击:

how do I generate random timestamps in Excel

excelexcel-vbaexcel-2013vba

提问by Cocoa Dev

I need to generate a bunch of random times in Excel 2013.

我需要在 Excel 2013 中生成一堆随机时间。

The time needs to be between 7AM to 8:45AM

时间需要在7AM到8:45AM之间

The number of rows varies but they are typically between 30 to 60

行数各不相同,但通常在 30 到 60 之间

回答by Werner

Using a formula in a cell (for times ranging from 7:00:00AM to 8:44:59AM):

在单元格中使用公式(时间范围从 7:00:00AM 到 8:44:59AM):

=TIME(7,RANDBETWEEN(0,104),RANDBETWEEN(0,59))

enter image description here

在此处输入图片说明

回答by Kenny

In Excel, one day = 1

在 Excel 中,一天 = 1

7AM = 7/24 845AM = 8.75/24

早上 7 点 = 7/24 845 点 = 8.75/24

Enter the formula:

输入公式:

=7/24+RAND()*(8.75/24-7/24)

On the Home tab of the Ribbon, select 'Time' from the dropdown in the Number area.

在功能区的“主页”选项卡上,从“数字”区域的下拉列表中选择“时间”。

This will generate a random time starting at 7am and continuing through 845am.

这将生成从早上 7 点开始一直持续到早上 845 点的随机时间。

回答by Gary's Student

Fill the cells with:

填充单元格:

=RAND()*(0.364583-0.291667)+0.291667

=RAND()*(0.364583-0.291667)+0.291667

回答by sujith

you want to generate random time between two given times, such as generate time from 6 o'clock to 9 o'clock, you can use below formula. Type this formula: =TEXT(RAND()*(8:45-7)/24+6/24,"HH:MM:SS") into a blank cell, and drag the fill handle over to the range that you want to insert the time.

您想在两个给定时间之间生成随机时间,例如从 6 点到 9 点生成时间,您可以使用以下公式。在空白单元格中键入此公式:=TEXT(RAND()*(8:45-7)/24+6/24,"HH:MM:SS") 并将填充手柄拖动到您想要的范围插入时间。