clear cells if time is < 0400

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,462
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.
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

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
 

Watch MrExcel Video

Forum statistics

Threads
1,108,502
Messages
5,523,296
Members
409,508
Latest member
Afc

This Week's Hot Topics

Top