I am trying to figure out the following. I have a list of employees that have a start-time and end-time in cells.
I want to try and calculate the number of employees that work during:
1. 8am-11am
2. 8am-5pm
3. 5pm-10pm
An example of the data is:
I think I may have to do something like this:
Set range = C1:Cxx (xx is the end of the range)
set counter = 0
for each cell in the range
if cell.value > "08:00 am" and cell.value < "11:00 am"
counter = counter + 1
set morningshift cell value to counter
end if
next
for each cell in the range
if cell.value > "08:00 am" and cell.value < "5:00 pm"
counter = counter + 1
set afternoonshift cell value to counter
end if
next
for each cell in the range
if cell.value > "5:00 pm" and cell.value < "10:00 pm"
counter = counter + 1
set eveningshift cell value to counter
end if
next
I am just not having much luck putting this into the right code. I though about using the Excel builtin function COUNTIF, but that just started to get extrememly complicated, so I thought a bit of code would work better.
Can anyone lend some assistance and let me know if I am going dopwn the right path as well, or suggest a better way?
Lastly, how do I make the code execute automatically? I don't care if it runs each time data is entered into a cell, I just don't really want the person to have to press a button to initiate it.
thanks,
Michael
I want to try and calculate the number of employees that work during:
1. 8am-11am
2. 8am-5pm
3. 5pm-10pm
An example of the data is:
Code:
A B C
1 John Doe Start 08:00 am
2 End 05:00 pm
3 Jane Doe Start 08:00 am
4 End 10:30am
.
.
.
Set range = C1:Cxx (xx is the end of the range)
set counter = 0
for each cell in the range
if cell.value > "08:00 am" and cell.value < "11:00 am"
counter = counter + 1
set morningshift cell value to counter
end if
next
for each cell in the range
if cell.value > "08:00 am" and cell.value < "5:00 pm"
counter = counter + 1
set afternoonshift cell value to counter
end if
next
for each cell in the range
if cell.value > "5:00 pm" and cell.value < "10:00 pm"
counter = counter + 1
set eveningshift cell value to counter
end if
next
I am just not having much luck putting this into the right code. I though about using the Excel builtin function COUNTIF, but that just started to get extrememly complicated, so I thought a bit of code would work better.
Can anyone lend some assistance and let me know if I am going dopwn the right path as well, or suggest a better way?
Lastly, how do I make the code execute automatically? I don't care if it runs each time data is entered into a cell, I just don't really want the person to have to press a button to initiate it.
thanks,
Michael