Check this out!

Ralph M

Well-known Member
Joined
Apr 16, 2002
Messages
502
Office Version
  1. 2016
Platform
  1. Windows
I would like to write my code in WorkSheet Change to check for an expiration date. "Z4" is a user entered date, "AA3" and "AB3" are user entered dates. When the user enters data into the cells under "AA" and "AB", Excel checks the two dates above and if one of them are expired, MsgBox. I can't write it to work correctly. Please help?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi,
Do you have an example of what the test is for the expiration?

otherwise something generic

Code:
dim countrow as long
dim count as long
 
count = 1
countrow = sheets("Sheet1").rows.count
 
do until count = countrow
if sheets("Sheet1").range("AA"&count) = 'a check then
msgbox ("hi")
else
'do code
end if
 
count = count + 1
loop
 
Upvote 0
When the user enters data into the Cell, the code checks the two dates to see if they are > now(). If they have expired, then magbox.
 
Upvote 0
ok so something like the below

Code:
dim countrow as long
dim count as long
 
count = 1
countrow = sheets("Sheet1").rows.count
 
do until count = countrow
if sheets("Sheet1").range("AA"&count) > now() then
msgbox ("hi")
else
'do code
end if
 
count = count + 1
loop
 
Upvote 0
OK, how about, when the user enters data, check the date in both cells, if it is < now() then msgbox? My code is :

If Target < -0 And Target.Column = 27 Or Target.Column = 28 Or Target.Column = 29 Or Target.Column = 30 And Not Target.Address = "$Z$4" And Not Target.Address = "$AA$2:$AD$4" Then


MsgBox ActiveSheet.Name & " 's Time has EXPIRED! Please update the FMLA dates."

But everytime I enter data, the msgbox appears, even if the dates in the two cells are in the future.
 
Upvote 0
If Target < -0 And Target.Column = 27 Or Target.Column = 28 Or Target.Column = 29 Or Target.Column = 30 And Not Target.Address = "$Z$4" And Not Target.Address "= "$AA$2:$AD$4" and activecell.range ("Z4") < -0 or activecell.range ("AA4") < -0 then


MsgBox ActiveSheet.Name & " 's Time has EXPIRED! Please update the FMLA dates."
Else
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

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