#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default excel VBA code

Any idea how to use VBA code to check if the current day is a
particular day ?
example : check if today is saturday
thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default excel VBA code

In Excel,
=weekday(today())
would tell you the day of week with 1 being a Sunday.

In VBA, you can use
Weekday(Now())
to return the day of the week.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html

"Savio" wrote in message
...
Any idea how to use VBA code to check if the current day is a
particular day ?
example : check if today is saturday
thanks


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 747
Default excel VBA code

Sub test()
dys = Format(Date, "dddd")
MsgBox "Today is " & UCase(dys)
End Sub


On Feb 1, 10:04*pm, Savio wrote:
Any idea how to use VBA code to check if the current day is a
particular day ?
example : check if today is saturday
thanks


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default excel VBA code

MsgBox Weekday(Date)
MsgBox Format(Date, "dddd")

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Savio" wrote in message
...
Any idea how to use VBA code to check if the current day is a
particular day ?
example : check if today is saturday
thanks


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default excel VBA code

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?


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 747
Default excel VBA code

Sub test()
dys = Format(Date, "dddd")
If dys = "saturday" Then
' your code goes here
Else
' your code
End If
End Sub



On Feb 1, 10:46*pm, Savio wrote:
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?


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default excel VBA code

perfect thanks!
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 947
Default excel VBA code

Instead of generating a string ("saturday") perhaps...

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

= = =
Dana DeLouis


Savio wrote:
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?

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,346
Default excel VBA code

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



--
If this helps, please click the Yes button

Cheers,
Shane Devenshire


"Dana DeLouis" wrote:

Instead of generating a string ("saturday") perhaps...

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

= = =
Dana DeLouis


Savio wrote:
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?


  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 947
Default excel VBA code

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


Shane Devenshire wrote:
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





  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 47
Default excel VBA code

You can use the following macro code to do that.
Please follow following steps
1.Right click on toolbar and click control box
2.From the control box that aooears, select command button and draw it on
your sheet
3.Double click on the command button to open the code and paste following
codes
Private Sub CommandButton1_Click()
Dim dt As Date

If Weekday(Now) = 7 Then
MsgBox "today is Saturday"
End If
End Sub

Hope you get it!

Have a nice time

Chris
------
Convert your Excel spreadsheet into an online calculator.
http://www.spreadsheetconverter.com

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200902/1

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to conditional format all black after date specified in code? wx4usa Excel Discussion (Misc queries) 3 December 26th 08 07:06 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
Convert a Number Code to a Text Code Traye Excel Discussion (Misc queries) 3 April 6th 07 09:54 PM
Unprotect Code Module in Code Damien Excel Discussion (Misc queries) 2 April 18th 06 03:10 PM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM


All times are GMT +1. The time now is 08:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"