cleaning up code

arelh

New Member
Joined
Dec 14, 2004
Messages
17
This macro creates a file that checks whether a macro has been run today or not - it assumes that a file named datestamp.xls exists - how can i clean up the code
regds to all Arelh

Sub datestamp()
Workbooks.Open Filename:="datestamp.xls"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Range("B1").Select
Selection.NumberFormat = "0.00"
ActiveCell.FormulaR1C1 = "=R[1]C[-1]-RC[-1]" '
Range("B2").Select
If Range("b1") > 0 Then
ActiveWindow.Close SaveChanges:=True
Workbooks.Add
ActiveCell.FormulaR1C1 = "= value(TODAY())"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2").Select
SaveFileName = "datestamp.xls"
DataFile = SaveFileName
TestData = Dir(DataFile)
If Len(TestData) > 0 Then Kill DataFile
ActiveWorkbook.SaveAs Filename:=DataFile, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close SaveChanges:=True
ElseIf Range("b1") = 0 Then
ActiveWindow.Close SaveChanges:=True
End
End If
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Nimrod

MrExcel MVP
Joined
Apr 29, 2002
Messages
6,259
Sub datestampV2()
Workbooks.Open Filename:="datestamp.xls"

Select Case Date - Range("A1")
Case 0
ActiveWindow.Close SaveChanges:=True
Case Is > 0
ActiveWindow.Close SaveChanges:=True
Workbooks.Add
ActiveCell.Value = Date
If Len(Dir("datestamp.xls")) > 0 Then Kill DataFile
ActiveWorkbook.SaveAs Filename:="datestamp.xls"
ActiveWindow.Close SaveChanges:=True
Case Else
End Select
End Sub
 

arelh

New Member
Joined
Dec 14, 2004
Messages
17
Thanks nimrod - the reason datafile and savefilename are there is because therer are many files created in the other macros - the variable date in the case statement is to be declared as today()?
regds rob
 

Forum statistics

Threads
1,148,525
Messages
5,747,188
Members
424,068
Latest member
Salim khamis

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