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

LVL 1
csehzIT consultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.