我刚开始编写Excel VBA脚本,但是我试图创建一个脚本,该脚本根据事件的开始时间和结束时间来截断事件的出勤率。现在,我有一张工作表,其中显示了所有参与活动的活动在所有参与的房间之间的分配情况,但是显示该活动是一天中的24小时。因此,我正在创建一个Do While循环,该循环将在开始时间和结束时间之外的时间内将出勤率设置为零,并在该事件时间内填充出勤率表。
问题是我在经历一系列事件时遇到了麻烦。这是我要填充以供参考的表。
Date Useage Event Time Meeting Room 1 Meeting Room 2 Meeting Room 3
01-01-18 3 12:00 AM
01-01-18 3 01:00 AM
01-01-18 3 02:00 AM
01-01-18 3 03:00 AM
01-01-18 3 04:00 AM
01-01-18 3 05:00 AM
01-01-18 3 06:00 AM
01-01-18 3 07:00 AM
01-01-18 3 08:00 AM
01-01-18 3 09:00 AM
01-01-18 3 10:00 AM
01-01-18 3 11:00 AM
01-01-18 3 12:00 PM
01-01-18 3 01:00 PM
01-01-18 3 02:00 PM
01-01-18 3 03:00 PM
01-01-18 3 04:00 PM
01-01-18 3 05:00 PM
01-01-18 3 06:00 PM
01-01-18 3 07:00 PM
01-01-18 3 08:00 PM
01-01-18 3 09:00 PM
01-01-18 3 10:00 PM
01-01-18 3 11:00 PM
01-02-18 3 12:00 AM
01-02-18 3 01:00 AM
Dim x As Double
Dim y As Double
Dim startTime As Double
Dim eventTime As Range
x = 0
y = 0
startTime = ActiveWorkbook.Sheets("Attendance").Range("H3")
Set eventTime = ActiveWorkbook.Sheets("Time Occupancy Analysis").Range("C2")
Do While (startTime >= eventTime) And y <= 24
Do While (startTime >= eventTime) And x <= 36
eventTime.Offset(0, x + 1) = 0
x = x + 1
Loop
x = 0
Sheets("Time Occupancy Analysis").Range("D2").Offset(y + 1, 0) = 0
y = y + 1
eventTime = eventTime + 0.04167 'This is where the problem exists'
Loop
我希望代码输出0出席,直到事件的startTime等于eventTime。运行时,它会更改eventTime而不是在事件时间范围(12:00 AM,1:00 AM,2:00 AM等)之间移动