VBA to reset my sheet when the file is opened for the first time each day.

danbates77

New Member
Joined
Jan 10, 2017
Messages
36
Office Version
  1. 2016
Hi,

Please could someone help me?

Does anyone know a way of resetting a sheet via VBA when the file is opened for the very first time each morning and only the very first time because the file will be opened multiple times per day but I only need it to reset on the very first occasion.

Any help would be very appreciated.

Thanks

Dan
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,

Please could someone help me?

Does anyone know a way of resetting a sheet via VBA when the file is opened for the very first time each morning and only the very first time because the file will be opened multiple times per day but I only need it to reset on the very first occasion.

Any help would be very appreciated.

Thanks

Dan
Define: "resetting a sheet"

I'm not familiar with that term.
 
Upvote 0
Hi,

So let's say I have random numbers in cells A1 down to A10 with various numbers in them. I would like all the cells from A1 to A10 to be reset back to zero when the file is opened for the very first time in the morning after 6am but I don't want the cells to be reset when the file is opened for the second time or third time and so on.

I hope this helps a little more.
 
Upvote 0
Hi,

So let's say I have random numbers in cells A1 down to A10 with various numbers in them. I would like all the cells from A1 to A10 to be reset back to zero when the file is opened for the very first time in the morning after 6am but I don't want the cells to be reset when the file is opened for the second time or third time and so on.

I hope this helps a little more.

So let's say you just have a cell somewhere with the date.
This will check the date. If current date is later than the date saved, it will clear contents of cells.
Just set the range.
After it's cleared it will input the current date to the chosen cell.

When current date = date in cell, then it won't run.

I placed this in ThisWorkbook.

Replace B1 with an empty cell somewhere. Enter today's date if you already opened it the first time today.

Tested and working.


VBA Code:
Private Sub Workbook_Open()

    Application.EnableEvents = False

    If Date > Range("B1").Value Then
        Worksheets("Sheet1").Range("A1:10").ClearContents
        Range("B1").Value = Date
    End If
 
        Application.EnableEvents = True

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,165
Messages
6,123,387
Members
449,098
Latest member
ArturS75

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