VBA Message box to appear if Cell value changes before a certain time.

Dgenty

New Member
Joined
Sep 8, 2014
Messages
19
Morning,

I need to get a message box to appear if a cell value changes from a "O" to a "C" before 17:00 on any given day. After this time the message box does not need to appear.

So basically the VBA equivalent of if A1 value = "C" and Time<="17,0,0" then message box "A1 =C"

Any help would be appreciated.
 

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.
try the below worksheet change event in the sheet object module

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim datecheck As String
If Target.Address = "$A$1" Then
datecheck = Format(Date & " 17:00:00", "dd/mm/yyy hh:mm:ss")
If Format(Now(), "dd/mm/yyy hh:mm:ss") <= datecheck Then
Target.Value = "O"
End If
End If

End Sub
 
Last edited:
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim datecheck As String
If Target.Address = "$A$1" Then
datecheck = Format(Date & " 17:00:00", "dd/mm/yyy hh:mm:ss")
If Format(Now(), "dd/mm/yyy hh:mm:ss") <= datecheck Then
msgbox "target value has changed"
End If
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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