How to automatically delete cell contents in excel after a week and after a day

malotic

New Member
Joined
Nov 5, 2022
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Good day! I would like to have a code that deletes the contents in B7 every 12AM sunday and deletes the range M3 to M23 every day at midnight. I dont have any knowledge on macros. Thank you

1667626721174.png
 

Attachments

  • 1667626640395.png
    1667626640395.png
    21.2 KB · Views: 19

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You will need to use Windows Task Scheduler to automatically open the excel file and run the required macros.

The above WTS link is for Win10. If you run a different Windows version, do a new Google search.
 
Upvote 0
I actually have a macro code for M3:M23 i just dont know what code and where to the code that removes B7 also but it is done every week. If deleting the content in B7 can't be done using a macro, HOW ABOUT deleting the content in B7 every after 5 days


VBA Code:
Private Sub Workbook_Open()
    If Sheets("Aux").Range("A1").Value < Date Then
        Sheets("CAPITAL").Range("M3:M23").ClearContents
    End If
    Sheets("Aux").Range("A1").Value = Date
End Sub
 
Upvote 0
Would this work for you ?
VBA Code:
Private Sub Workbook_Open()

    If Sheets("Aux").Range("A1").Value < Date Then
        Sheets("CAPITAL").Range("M3:M23").ClearContents
    End If
    Sheets("Aux").Range("A1").Value = Date
    
    If Weekday(Date, vbSunday) = 1 Then
        Sheets("CAPITAL").Range("B7").ClearContents
    End If

End Sub
 
Upvote 0
Solution
Thank you very much! Don't know how to test this without actually waiting for sunday midnight, so i'll get back to you :)
 
Upvote 0
I just copied the code somewhere here in mr excel so i just wanna ask if the last part actually ends with "end if .. end sub" without these " Sheets("Aux").Range("A1").Value = Date"


VBA Code:
 If Weekday(Date, vbSunday) = 1 Then
        Sheets("CAPITAL").Range("B7").ClearContents
    End If

End Sub
 
Upvote 0
Thank you very much! Don't know how to test this without actually waiting for sunday midnight, so i'll get back to you :)
FYI, the code won't run until you first manually open the workbook. The code won't run by itself on sunday midnight even if the workbook is left is open
 
Upvote 0
I just copied the code somewhere here in mr excel so i just wanna ask if the last part actually ends with "end if .. end sub" without these " Sheets("Aux").Range("A1").Value = Date"


VBA Code:
 If Weekday(Date, vbSunday) = 1 Then
        Sheets("CAPITAL").Range("B7").ClearContents
    End If

End Sub
Just remove the line Sheets("Aux").Range("A1").Value = Date and leave the rest of the code in post#4 as is.
 
Upvote 0
Would this work for you ?
VBA Code:
Private Sub Workbook_Open()

    If Sheets("Aux").Range("A1").Value < Date Then
        Sheets("CAPITAL").Range("M3:M23").ClearContents
    End If
    Sheets("Aux").Range("A1").Value = Date
   
    If Weekday(Date, vbSunday) = 1 Then
        Sheets("CAPITAL").Range("B7").ClearContents
    End If

End Sub
WORKS GREAT! Manually changed the date in my pc a few times and saw that the B7 is removed every sunday only. THANK YOU VERY MUCH
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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