Visual Basic - I'm stuck
Posted by May on December 28, 2001 2:20 PM
I am working on a project in excel that'll automatically add 4 hours of leave to each employee on the 1st of the month. So far (thanks to someone on this site) I have it set up to add the 4 hours on the 1st, but I have to manually run the maco myself on the 1st. I want the macro to run automatically when I open the worksheet on the 1st (it can only run once incase I open the sheet several times on the 1st). I've placed what I have so far below. Can someone e-mail me the corrected code? Also is there a way to include in the code that if the 1st lands on the weekend and no one opens the sheet to run the macro it'll check 3 days back on Monday and if the code hasn't run to go ahead and run it. If anyone can help I'd really really appreciate it. thanks!
Public Sub FirstOfMonth()
FOM = Format(Date, "dd")
If FOM = 1 Then
Range("C3").Select ' Enter starting point in sheet
Do
OriginalTime = ActiveCell.Value
ActiveCell.FormulaR1C1 = (OriginalTime + "4")
ActiveCell.Offset(RowOffset:=1).Activate
Loop Until ActiveCell.Row = "20" 'Enter final point in sheet
End If
End Sub