Time Issues

bhachug

New Member
Joined
Sep 30, 2011
Messages
15
Hey guys I'm trying to input a time from a cell into a VBA code and have it round to hours and store it in a variable so that it can be tested against a condition. At the moment I have


tempHour = Format(ActiveSheet.Range("C10").Select, "hh")
If (tempHour = 23) Or (tempHour < 7) Then
CurrentShiftName = "Shift 1"
ElseIf (tempHour >= 7 And tempHour < 15) Then
CurrentShiftName = "Shift 2"
ElseIf (tempHour >= 15 And tempHour < 23) Then
CurrentShiftName = "Shift 3"


tempHour is the integer name I'm using to store the time. I'm not sure if that Format() is correct because when I try and troubleshoot it I see that tempHour never changes from 0. The cell that's I understand to be inputted into the formula is just a cell I've formatted to display the 24 hour time. Any help would be appreciated. For the record CurrentShiftName always outputs Shift 1 since temphour never seems to change from zero.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
try:

Code:
tempHour = Format(ActiveSheet.Range("C10").value, "hh")
Never use .select in this context, in fact avoid using it as much as possible.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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