if cell is a certain day macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need help with writing a macro that would run if and only if the date value
in A1 is a Tuesday. The date written in A1 is in the format dd-mm-yyyy. If
it is a Tuesday, then the macro would call a seperate private macro named
TuesdayMacro. Is there any way to do that?

Thanks!
 
Do you want the macro to run automatically whenever the data in A1 is
changed? If so, you could right click on your sheet tab, select view code
and paste the following into the code window.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then _
If Application.Weekday(Target.Value) = 3 Then
Call TuesdayMacro
End Sub


If you want to decide when you want to run it, you can put this into a
regular VBA module (and attach it to a button or call it from other code):

Sub TestDay()
If Application.Weekday(Worksheets("Sheet1").Range("A1").Value) = 3 Then _
Call TuesdayMacro
End Sub
 
Thank you! The second one is exactly what I needed, but it is nice to know
the first option as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top