VBA formula based from NOW

poikl

Active Member
Joined
Jun 8, 2002
Messages
484
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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