Hello! Anybody have any ideas why this is happening? Thank you!
I have 2 variables declared as Variants (they are times, and I suppose could use Date as well but have been trouble-shooting):
dim timeStart as Variant
dim timeEnd as Variant
They essentially test if a value in a data set are between an hourly range (for instance: 1:00 AM - 2:00 AM). If the value is between a range, I perform a few calculations and want to report the sum for each data point, for each hour. See the Worksheet image attached.
Worksheet.jpg
The problem I am having is when I want to populate this Worksheet I have been running the following code:
Range("B2").Select 'Selects the time header row
While ActiveCell.Value <> timeStart 'While the active cell is not equal to the start of the hour value
ActiveCell.Offset(0, 1).Select
Wend
I want to move to the right to column B, C, D, etc until I reach the accurate time, and then fill in the proper row with a returned value.
Problem: For some reason it seems to work until 2:00 AM. I added a watch, and even though the timeStart value is found to equal 2:00 AM, and the Active Cell is over 2:00 AM, it never leaves the While and just moves to the next time. See attachment:
Works: works.jpg
The loop exits and will proceed normally.
Doesn't Work:doesnt_work.jpg
Even though the code is the same, timeStart is 2:00:00 AM and the cell is over 2:00:00 AM, it never exits the loop.
Any ideas? I see the ActiveCell.Value is reading an odd number - but it still works for the times of 0:00 and 1:00. I tried different formatting but no luck. Thanks in advance!
Bookmarks