[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

Excel VBA - Weekday check

Dear Experts,

Can you please have a short look in the attached code, I would like to check what is the todays day in weekday and if it is 4, then assign to a variable 6, and if it is different than 4 then assign the current weekday.

For sure this line has the error FileNap = Evaluate("=IF(MilyenNap=4,6,MilyenNap)")

thanks,

Sub DayCheck()
Dim MilyenNap As Long
Dim FileNap As Long

MilyenNap = Weekday(Date)
FileNap = Evaluate("=IF(MilyenNap=4,6,MilyenNap)")
MsgBox FileNap
End Sub

Open in new window

0
csehz
Asked:
csehz
  • 3
  • 2
2 Solutions
 
spattewarCommented:
Hello csehz,

Can you try this code?

Sub DayCheck()
Dim MilyenNap As Long
Dim FileNap As Long

MilyenNap = Weekday(Date)
If MilyenNap = 4 Then
FileNap = 6
Else
FileNap = MilyenNap
End IF
MsgBox FileNap
End Sub


Regards,

spattewar
0
 
TracyVBA DeveloperCommented:
Try this:
Sub DayCheck()
    Dim MilyenNap As Long
    Dim FileNap As Long
    
    MilyenNap = Weekday(Date)
    
    If MilyenNap = 4 Then
        MilyenNap = 6
    Else
    End If
    
    MsgBox MilyenNap
End Sub

Open in new window

0
 
TracyVBA DeveloperCommented:
oops, didn't see your post spattewar
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
csehzIT consultantAuthor Commented:
Thanks very much for both, of course the issue is resolved.

May I ask what is the problem in the evaluate formula? Somehow I never know that in which cases can be used.

0
 
TracyVBA DeveloperCommented:
The way you're using it, you're using it as Text, so it's not evaluating the variables.
("=IF(MilyenNap=4,6,MilyenNap)")

If you want it to evalute variables then you would have to do something like this:
("=IF(" & MilyenNap & "=4,6," & MilyenNap & ")")

This will recognize the variable value.
0
 
csehzIT consultantAuthor Commented:
Broomee 9 it is very good, I mean learnt with it the variables using inside the evaluate.

Thanks very much, the points will not expressing completely because would like to thanks also to spattewar.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now