View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
[email protected][_2_] HammerJoe@gmail.com[_2_] is offline
external usenet poster
 
Posts: 5
Default Simple if formula in a macro

Thanks,

It works.

How do you make it so that it autoruns when the worksheet is opened?

Thanks again.

Dave Peterson wrote:
Option Explicit
Sub Auto_Open()

Dim myCell As Range
Dim wks As Worksheet

Set wks = ThisWorkbook.Worksheets("sheet1")

Set myCell = wks.Range("a26")

If IsEmpty(myCell.Value) Then
myCell.Value = Date
ElseIf IsDate(myCell.Value) Then
If myCell.Value < Date Then
myCell.Value = Date
End If
End If

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

wrote:

Hi folks,

I have a very simple request, but my VBA days are way gone and I dont
really know how it works with excell.

All I need is a IF statement that checks cell A26 to see if it is empty
or if it includes a date entry (IE nov/11).

If the cell is empty or if the date is equal to at least today then do
nothing.
If the date in the cell is older than todays date, then call sub
routine and put today date on cell a26.

Thats it.

I plan on assigning this macro to a button, but it would be better if
this routine was run automatically everytime the worksheet was opened,
how is it done?

Thanks


--

Dave Peterson