Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
excel VBA code
perfect thanks!
|
#8
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Code to conditional format all black after date specified in code? | Excel Discussion (Misc queries) | |||
Drop Down/List w/Code and Definition, only code entered when selec | Excel Worksheet Functions | |||
Convert a Number Code to a Text Code | Excel Discussion (Misc queries) | |||
Unprotect Code Module in Code | Excel Discussion (Misc queries) | |||
copying vba code to a standard code module | Excel Discussion (Misc queries) |