ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   excel VBA code (https://www.excelbanter.com/excel-discussion-misc-queries/218668-excel-vba-code.html)

Savio

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


Chirag

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



muddan madhu

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



Don Guillett

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



Savio

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?

muddan madhu

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?



Savio

excel VBA code
 
perfect thanks!

Dana DeLouis

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?


Shane Devenshire[_2_]

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?



Dana DeLouis

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




Chris Bode via OfficeKB.com

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



All times are GMT +1. The time now is 01:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com