Macro to clear cell contents based on IF date in another cell = today

rabidcabbage

New Member
Joined
Feb 4, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I am trying to build a macro that will clear contents of the cell that holds the PTO taken based on hire date to the year mark (if the employee has passed their 1 year anniversary) and at to the 6 month mark (if the employee has passed their 5 year anniversary).

So a macro that will clear the contents of Cell D11 if [B23 >= today's date AND if B27 = today's date] or [B20 >= today's date AND if B26 = today's date]. Attached is a mock worksheet, which is the style we will build out for each employee. So I am wanting the macro to run this process if the worksheet is the active window. Is this even possible?
 

Attachments

  • Tracker.JPG
    Tracker.JPG
    57.2 KB · Views: 27

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You can use the Worksheet_Activate event.

VBA Code:
Private Sub Worksheet_Activate()
'your code here
End Sub
 
Upvote 0
You can do something like this:

VBA Code:
If (Range("B23").Value >= Date And Range("B27").Value = Date) Or _
   (Range("B20").Value >= Date And Range("B26").Value = Date) Then
    Range("D11").ClearContents
End If
 
Upvote 0
You can do something like this:

VBA Code:
If (Range("B23").Value >= Date And Range("B27").Value = Date) Or _
   (Range("B20").Value >= Date And Range("B26").Value = Date) Then
    Range("D11").ClearContents
End If

So written very differently from formulas in a cell.
So you use
Code:
  vs "Sub" I have been seeing used for excel vba?
 
Upvote 0
So I was able to perform the Macro, but I had to invert the Date / Range fields. Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,058
Latest member
oculus

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