clear cells if time is < 0400

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,546
Members
449,038
Latest member
Guest1337

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