VBA Code based on NOW (time)

poikl

Active Member
Joined
Jun 8, 2002
Messages
484
Platform
  1. Windows
Hi,
I have the following code in MACRO in ColM to enter initials based on the NOW entry in ColA. However it always enters FM no matter what time so it's not working!
In ColM I have entered "Cells(c.Row, "m").Formula = "=IF(RC[-12]<=TIMEVALUE(""3:50:00 PM""),""RB"",""FM"")"
In ColA I have:"Cells(c.Row, "A").Value = Format(Date, "m/d/yy") & " " & Format(Time, "hh:mm:ss")
Can you please help correct the code so that an entry after 3:50PM shows "FM" and anything earlier (of same date) shows "RB"?
 
Sorry,No, I wasn’t aware of that. I was under the impression that the date and time was already picked up in the adjacent row ColA from the code “"Cells(c.Row, "A").Value = Format(Date, "m/d/yy") & " " & Format(Time, "hh:mm:ss")”.
(BTW, the running log sheet I’m using is already at row 2169. I don’t know if that makes a difference but figured just to throw that out just in case).
Can’t thank you enough Mark for all your efforts on this project
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Sorry,No, I wasn’t aware of that
It's been there since post 9

(BTW, the running log sheet I’m using is already at row 2169. I don’t know if that makes a difference but figured just to throw that out just in case).
Definitely makes a difference that the
Excel Formula:
=TODAY()
needs to be in a separate cell and not in the formula

Sorry,No, I wasn’t aware of that. I was under the impression that the date and time was already picked up in the adjacent row ColA from the code “"Cells(c.Row, "A").Value = Format(Date, "m/d/yy") & " " & Format(Time, "hh:mm:ss")”.
You haven't stated anywhere in the post what code (if any) you are using for cells other than the partial code for column M so I wouldn't be aware that you had it.

That line can be written as just
VBA Code:
Cells(c.Row, "A").Value = Format(Now, "m/d/yy hh:mm:ss")
btw

Whether you can reference the column A value rather than using =TODAY() only you will know, as only you know how your worksheet works and what you are trying to compare.
 
Last edited:
Upvote 0
Solution
Mark, Thank you, thank you, thank you. I entered all the information per your instructions and it works exactly as was needed. Have a wonderful day
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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