When WorkBook Opens, If Then

suthern_gntlman

New Member
Joined
Feb 17, 2010
Messages
9
A commandbutton copies Daily Lab.xlsm and saves it into a dir, based upon a Date in a certain cell. (used a code from MrExcel forums) It Works great, btw....

Ex: Daily Lab.xlsm has a date in "C6" of 2/23/2010. It saves it into the Daily Lab\2010\FEB dir, as Feb232010.xlsm (creates dir when month and year changes)

The macro I created then clears all data from Daily Lab.xlsm, saves and closes it. When the LabTech opens it up all data (including previous date) must be gone. I used the following code to accomplish this:

In ThisWorkBook:
Code:
 Private Sub Workbook_Open()
'CLEARS DATE FOR FRESH DATA ENTRY
        Range("C6").Select
        Selection.ClearContents
    
End Sub
My Problem: I need the macro to stay in Feb232010.xlsm for other reasons.

Unknown solution: I would like to use an "If Then" in ThisWorkBook that upon opening will look at the Date in "C6" and compare it to the name of the WorkBook. If they equal then the date stays, if they don't equal the date clears.

I'm able to understand what code does once I see it, but having a real hard time creating it from scratch... :)

Thanks in advance...
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
We're assuming you have only sheet of course... or that the file is always opened on appropriate sheet....

Code:
Private Sub Workbook_Open()
'CLEARS DATE FOR FRESH DATA ENTRY
With Range("C6")
    If Format(.Value,"mmmddmmyyyy") & ".xlsm" = ThisWorkbook.Name Then .ClearContents
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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