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

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.

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
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

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
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,191,627
Messages
5,987,756
Members
440,107
Latest member
stefanyelas

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
Top