ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   IF statement Help (https://www.excelbanter.com/excel-programming/283052-if-statement-help.html)

John G[_4_]

IF statement Help
 
Is there a way I can do the following to force a date
change according to a certain time. In cell b5 I have =Now
(), and that returns todays date. If the time is between
midnight and six am I would like the date to go back one
day, such as =Now()-1.

Even if I have to make a button to run macro that would
be OK. I just can't figure out the IF statement that
would compare the times.

I want it to read something like this; if the time is
between 00:00:00 and 06:00:00 then Now()-1 else Now()

Thanks in advance for your help

John G

GJones

IF statement Help
 
John;

Create a macro that contains:

If hour(now)<6 then Range("A1") = Date -1

Else Range("A1") = Date

End If





-----Original Message-----
Is there a way I can do the following to force a date
change according to a certain time. In cell b5 I have =Now
(), and that returns todays date. If the time is between
midnight and six am I would like the date to go back one
day, such as =Now()-1.

Even if I have to make a button to run macro that would
be OK. I just can't figure out the IF statement that
would compare the times.

I want it to read something like this; if the time is
between 00:00:00 and 06:00:00 then Now()-1 else Now()

Thanks in advance for your help

John G
.


Tom Ogilvy

IF statement Help
 
=IF(HOUR(NOW())<6,NOW()-1,NOW())

--
Regards,
Tom Ogilvy

John G wrote in message
...
Is there a way I can do the following to force a date
change according to a certain time. In cell b5 I have =Now
(), and that returns todays date. If the time is between
midnight and six am I would like the date to go back one
day, such as =Now()-1.

Even if I have to make a button to run macro that would
be OK. I just can't figure out the IF statement that
would compare the times.

I want it to read something like this; if the time is
between 00:00:00 and 06:00:00 then Now()-1 else Now()

Thanks in advance for your help

John G




John G.[_3_]

IF statement Help
 
Thank You very much for the reply Tom & GJones
-----Original Message-----
=IF(HOUR(NOW())<6,NOW()-1,NOW())

--
Regards,
Tom Ogilvy

John G wrote in

message
...
Is there a way I can do the following to force a date
change according to a certain time. In cell b5 I have

=Now
(), and that returns todays date. If the time is

between
midnight and six am I would like the date to go back

one
day, such as =Now()-1.

Even if I have to make a button to run macro that

would
be OK. I just can't figure out the IF statement that
would compare the times.

I want it to read something like this; if the time is
between 00:00:00 and 06:00:00 then Now()-1 else Now()

Thanks in advance for your help

John G



.



All times are GMT +1. The time now is 09:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com