excel VBA code

  • Thread starter Thread starter Savio
  • Start date Start date
S

Savio

Any idea how to use VBA code to check if the current day is a
particular day ?
example : check if today is saturday
thanks
 
Sub test()
dys = Format(Date, "dddd")
MsgBox "Today is " & UCase(dys)
End Sub
 
thanks. do you know how i could incorporate that into an if statement.
Say : if today is saturday, follow a set of commands, else do
something else?
 
Sub test()
dys = Format(Date, "dddd")
If dys = "saturday" Then
' your code goes here
Else
' your code
End If
End Sub
 
Instead of generating a string ("saturday") perhaps...

If Day(Date) = vbSaturday Then
'Your code...
Else
'Something else
End If

= = =
Dana DeLouis
 
Hi,

The Day function does not return the weekday it returns the day of the month.

Instead you could use

If Weekday(Date) = 7 Then

Else

End if

7 is the value for Saturday; Sunday = 1. If you're not coding a msgbox then
this would be a possibe branch.

If you want to handle the entire week consider using

Select Case Weekday(Date)
Case 1 'Sunday
'your code here
Case 2 'Monday
...

Case Else

End Select
 
Instead you could use
If Weekday(Date) = 7 Then

Oops! Thanks for the catch. Yes, I meant Weekday.

Instead of a string, or a number like 7, perhaps...

? VbSaturday
7

Hence...

If Weekday(Date) = vbSaturday Then...

= = =
Thanks again.
Dana
 

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