Verify Date and Time For Report Using VBA - excel

I have a spreadsheet with an input page that logs data on subsequent sheets. A macro will allow the user to input three date and time pieces for verifying how the data should be stored.
For example there is a Morning, Mid-Day, and Evening Report button; upon clicking the macro will verify the date and time fit into the appropriate window. My times are 8:00, 16:00, and 0:00 with the following code verifying the time falls into the correct window:
If Continue And reportdate - Int(reportdate) <> 0.33 Then
MsgBox ("The date and time are not correct for the Morning Report. Please change the time/date or select one of the other reports.")
Continue = False
End If
reportdate is the user input date and time for the report. The arithmetic = 0.33 and in my mind I am saying if the date and time doesn't match this value then the time frame isn't correct and a different report should be run. However, when I run this code for 8am the macro says it doesn't fall in the correct time window.

ok so as mentioned 0.33 is not actually 8am, it appears to be 7:55:12.
Using a stop and the locals window:
differenceValue = eightAm - midNight
Stop
Gives a difference value of 0.333333333335759.
You could use that or set up a differneceValue as above and compare to that.
Let me know if it works

Related

Excel VBA Scheduled message pop up box reminder

I want to create a script that sends a msg box at a specific time on a specific day of the week. eg every Monday at 10am.
Sub Reminder()
Dim time As Range
Set time = Sheets("Main").Range("W11")
If time.Value = "Monday 10:00" Then
MsgBox "Time reminder"
End If
End Sub
Tp try and make this work, I have a cell that's formatted to show the day and time in "W11" that's formatted to match the if function, but still doesn't seem to want to work. Note: I had it almost working before but not sure what I was doing differently, however the msgbox would pop up every time I clicked for the whole minute and wasn't only one instance. It seems like it should be really simple.
What is the exact contents of W11? When formatting a date in Excel, the actual contents doesn't change, only the appearance of that date. The content might be "1/1-2023 10:00", and the appearance "Monday 10:00". Which means that W11 is not equal to "Monday 10:00".
Also, the current code will never work as intended, unless the code is run at exactly monday at 10 am. You will need a time range, check if current date/time is larger than monday 10:00 or a constantly listinging "listener" to do that.
Provide some sample data, if you need further assistance.

Excel: Get the days delayed from Start date to End date Using DatedIF?

I have a sample data here that I want to get the days delayed.
As you can see,
The data shows the records for those users who did not submit their project, users who submitted on-time, and users who actually dont submit their project.
Currently,
I have this formula
=DATEDIF(A2,B2,"d")
for the first row to calculate the days delayed of first row.
Can I add in this formula that detects if the user dont submit their project and the delayed days continues counting for day delayed? Like for example the data on row 4. The column submitted_project is blank means the user still dont submit their project the days delayed will start counting after the deadline.
You don't need DateDif for that. (By the way it's Date-Dif for "date difference", not Dated-If)
You can simply subtract the two dates from each other and format the result as a number.
DateDif expects the earlier date as the first parameter, that's why it errors when the first parameter is the later date, i.e. when the project was submitted before the due date.
But with simple subtraction like =B2-A2 you can get the correct result. Better even, to check that both cells have dates before doing the calculation, to avoid misleading results, so
=if(count(A2:B2)=2,B2-A2,"")
Edit after comment: Yes.
=IF(COUNT(A5:B5)=2,B5-A5,IF(B5="",TODAY()-A5))

Excel (time format DD.MM.YY hh:mm) is not able to do proper time steps automatically

I have come across this problem several times, so I would like to ask you now. I often need to create time series with hourly time steps (usually for the length of one year).
So I start to write
01.01.2001 00:00
01.01.2001 01:00
01.01.2001 02:00
Then I drag the the fill handle, so that Excel automatically fills the next lines until 31.12.2001. But, for what reason ever, there is a sudden jump of only 59 minutes instead of a full hour:
05.01.2001 03:00
05.01.2001 03:59
05.01.2001 04:59
Anybody else who came across this? And can me explain the reason and/or recommend alternatives for an automatic creation of the time series?
In the first cell you need to change number format to
dd.mm.rrrr g:mm;#
Then you can write your first date and time. When you drag the fill to the second cell - edit it to get next hour. Then when you select this two cell and drag fill handle you'll get automatically time series +hour
picture

Formatting Existing Excel Cells to Time Format Without Date

I'm working on an excel 2010 sheet where I mark down the date and time an event happens. The date is in one column, and auto formats to 17-Nov when I would type in 11-17 (I was fine with this). The time is in a separate column.
I am trying to find the average time an event occurred, without regard to the date, so I would use =AVERAGE(C1:C10). However, I only receive a date back (like 17-APR).
I did not format the cells before I began to enter in data, and I would simply type in a 3:27pm event as 1527, and no reformatting would happen.
Now, when I attempt to reformat the column to hhmm, all the numbers entered so far turn to 0000. When I try to edit the 0000, it is formatted as 6/13/1906 12:00:00 AM.
What I want to do is have the time formatted as hhmm and not include a date in the cell, and be able to run formulas on it, such as the average time an even occurred.
Summary:
*Currently time is entered simply as ####. I entered 3:27pm as 1527.
*Trying to reformat the time column results in 0000 in all cells in the column that previously had a ####.
*Modifying the 0000 displays as 6/13/1906 12:00:00 AM
*I want to format the time as hhmm so I can simply type in 2357, and have it display as 2357, but understand I mean 11:57pm, and let me take averages.
*Hell, even being able to enter 1547 and have it auto format to 15:47 or 3:47p would be great.
Thanks for reading my question!
An easy way to apply an autoformat (though Excel won't see it as a true "Time") is to go into Format Cells>Custom> and use ##":"##. This will turn 1245 into 12:45. Mind you, this will be a text string so if you copy it to another cell and then apply a time, it will show as 12:00:00. Excel will also not be able to run formulas on it, but it's a quick and dirty way to make it look pretty.
Another option is to have a formula such as =TIME(LEFT(A1,2),RIGHT(A1,2),) where A1 would be replaced with the cell you are actually referencing. This will convert the number to a time that Excel will recognize as a time allowing you to run other functions on it, but requires another column.
If you are entering the times as 4-digit numbers, you'll need to do a calculation to get the hours and minutes, then use the TIME function to get an actual time:-
=TIME(A1/100,MOD(A1,100),0)
Another way is
=LEFT(A1,2)/24+RIGHT(A1,2)/1440
but then you have to format the result as a time.
Excel sees a number like 1547 as approximately 4 years on from 1st January 1900 if you format it as a date, so it will come out as something like 26/3/1904 in UK format or 3/26/1904 in US-style format.
Note that the time function can only give you values up to 23:59:59 (stored as 0.999988426), but the second method will give you a datetime value with one or more days as the whole number part. This can be useful if you want to do calculations on times spanning more than one day.
The above behaviour is because dates and times are stored as real numbers with the whole number part representing days and the decimal part representing fractions of a day (i.e. times). In spite of misleading information from Microsoft here, dates actually start from 31/12/1899 (written as 0/1/1900) with serial number 0 and increment by 1 per day from then on.

summing time excel spreadsheet not working

I have a issue with excel, I am trying to add up time so they can be displayed correctly in the spreadsheet that I am making, I have requests from user and give them how long it will take to change or fix. on the sheet I am displaying 01:00:00 which means the time taken is 1 hour, and displaying the sum usinfg =sum(A1:A10) which adds up fine when the time is under 24 hours, but if the sum is grater is show up as 03:00:00, i would like to know if it is possible to show time as 27:00:00 which means 27 hours the change will take. not three how would i allow this to be displayed
youu need to use the following custom cell format : [hh]:mm:ss

Resources