clear cells if time is < 0400

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,493
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

On worksheet open I want to clear the contents of cells A8:P50 if the date/time in cell AB1 is less than todays date and before the time 0400.

So currently AB1 shows
Code:
16/03/2011  07:32:40

so if the workbook was to be opened now nothing would be cleared however if the worksheet is opened before 0400 then A8:P50 of sheet DATA are cleared.

any help appreciated.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
Perhaps something along the lines of:

Code:
Private Sub Workbook_Open()
    With Sheets("Sheet1")
        If .Range("AB1") < Date + TimeSerial(4,0,0) Then
            .Range("A8:P50").ClearContents
        End If
    End With
End Sub

modify sheet object as appropriate of course
 

GregoryRicky

New Member
Joined
Apr 3, 2013
Messages
3
Hi, i have tried this and nothing seems to happen. I need to have a code that clears cell A5 and resets cell D5 to Yes or No



Perhaps something along the lines of:

Code:
Private Sub Workbook_Open()
    With Sheets("Sheet1")
        If .Range("AB1") < Date + TimeSerial(4,0,0) Then
            .Range("A8:P50").ClearContents
        End If
    End With
End Sub

modify sheet object as appropriate of course
 

Forum statistics

Threads
1,141,227
Messages
5,705,141
Members
421,380
Latest member
Nuwan Sanjeewa Aponso

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