简体   繁体   English

为B列中的每个日期填充B列中的时间范围

[英]fill a range on times in Column B for each date in Column A

I need to generate something like this in excel. 我需要在excel中生成类似的内容。 For each date in 'Date ' column, I need to fill times between 13:00 and 22:00 with 15 minute intervals. 对于“日期”列中的每个日期,我需要以15分钟为间隔填充13:00至22:00之间的时间。 Note: The dates in Column D are not serial. 注意:D列中的日期不是连续的。 They have to be taken from a list which can reside in another column/worksheet. 它们必须从可以驻留在另一列/工作表中的列表中获取。 Any help is appreciated on this. 任何帮助表示赞赏。

Date, Time
1 apr-2013, 13:00
1-apr-2013, 13:15
..
..
..
1-apr-2013, 22:00
2-apr-2013, 13:00
..
2-apr-2013, 22:00
8-apr-2013, 13:00
.
8-apr-2013, 22:00

This formula may work for you. 这个公式可能对您有用。 It will check to see if the date in the previous row is equal to the date in the current row; 它将检查上一行中的日期是否等于当前行中的日期; if it is not, then it will set the time as your start time (13:00). 如果不是,那么它将把时间设置为您的开始时间(13:00)。 If it is, then it adds 15 minutes to the time above the current row. 如果是这样,那么它将使当前行上方的时间增加15分钟。

=IF(A2<>A1,TIME(13,0,0),B1+TIME(0,15,0))

This formula can be placed next to all of your dates (in the time column) 该公式可以放在所有日期旁边(在“时间”列中)

You can probably use the DateAdd function in VBA. 您可能可以在VBA中使用DateAdd函数。 http://www.techonthenet.com/excel/formulas/dateadd.php http://www.techonthenet.com/excel/formulas/dateadd.php

For example, this would copy the date in cell A1 to A2 and add 15 minutes to it 例如,这会将单元格A1中的日期复制到A2并添加15分钟

Range("A2") = DateAdd("n", 15, Range("A1"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM