VBA formula based from NOW

poikl

Active Member
Joined
Jun 8, 2002
Messages
483
Platform
  1. Windows
Hi,
I have a colA which contains the NOW formula.
Can you please write a VBA MACRO formula to enter in ColK either RB If the adjacent ColA shows time equal or earlier than 3:00PM and if after then, FM?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You don't need VBA for this. You can use a formula in column K:

Excel Formula:
=IF(A1<=TIMEVALUE("3:00 PM"),"RB",FM")
 
Upvote 0
Hi, Thank you your formula is great and works though as a formula but I'd like to ask if you can write it out as code which I would be able to copy and paste?
 
Upvote 0
Maybe this?
VBA Code:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim cellA As Range
If Not Application.Intersect(Me.Range("K:K"), Target) Is Nothing Then
    Set cellA = Me.Cells(Target.Row, "A")
    Select Case Hour(cellA.Value)
        Case Is > Hour("3:00:00PM")
            Target.Value = "FM"
        Case Is < Hour("3:00:00PM")
            Target.Value = "RB"
    End Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,604
Messages
6,173,319
Members
452,510
Latest member
RCan29

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