Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,565 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,892 people online right now. Registration is fast and FREE... Join Now!




VBA - If time is between x and y on a monday....

 
Reply to this topicStart new topic

VBA - If time is between x and y on a monday...., not limited to that day of the week !

KG87
9 Apr, 2008 - 05:35 AM
Post #1

D.I.C Head
**

Joined: 25 Sep, 2007
Posts: 52



Thanked: 2 times
My Contributions
Im back again!


Im severely dissapointed my code is not finished!

The problem i have now, is that i need a check box to be checked if the time (placed in Cell(1,5)) is between set times

they are as follows

17:00 to 18:45 Mon, Tue, Wed, Thur, Sun
17:00 to 18:00 Fri, Sat

The code that i have doesn't seem to do anything.

The time in the Cell IS formatted as time, Does this need to be changed?


CODE

    If Weekday(Now()) = vbMonday Or vbTuesday Or vbWednesday Or vbThursday Or vbSunday And Cells(1, 5) > "17:00" < "18:45" Then
       chkfh.Value = True
           Else
       If Weekday(Now()) = vbFriday Or vbSaturday And Cells(1, 5) > "17:00" < "18:00" Then
           chkfh.Value = True
           Else
            chkfh.Value = False
        End If
    End If
    


Thanks everyone once again


(sorry martyr2 for no response to my last post Its been hectic as hell here!)
User is offlineProfile CardPM
+Quote Post

KG87
RE: VBA - If Time Is Between X And Y On A Monday....
10 Apr, 2008 - 03:54 PM
Post #2

D.I.C Head
**

Joined: 25 Sep, 2007
Posts: 52



Thanked: 2 times
My Contributions
May I bump this Question?

(feel free to delete if it violates TOC)
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: VBA - If Time Is Between X And Y On A Monday....
10 Apr, 2008 - 05:39 PM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You need to have an AND clause in your If statement. Also, when checking like you're doing (Weekday(Now()) = vbMonday) you have to have that for each or statement


vb

If ((Weekday(Now()) = vbMonday) Or (Weekday(Now()) = vbTuesday) Or _
(Weekday(Now()) = vbWednesday) Or (Weekday(Now()) =vbThursday) Or _
(Weekday(Now()) = vbSunday)) And (Cells(1, 5) > "17:00" And Cells(1,5) < "18:45") Then
chkfh.Value = True
Else
If Weekday(Now()) = vbFriday Or Weekday(Now()) = vbSaturday And Cells(1, 5) > "17:00" And Cells(1,5) < "18:00" Then
chkfh.Value = True
Else
chkfh.Value = False
End If
End If


Give that a shot and see what it does for you smile.gif

This post has been edited by PsychoCoder: 10 Apr, 2008 - 05:44 PM
User is offlineProfile CardPM
+Quote Post

KG87
RE: VBA - If Time Is Between X And Y On A Monday....
10 Apr, 2008 - 07:45 PM
Post #4

D.I.C Head
**

Joined: 25 Sep, 2007
Posts: 52



Thanked: 2 times
My Contributions
Thanks for the advice, though im currently documenting the existing one (made it manual)

So here's hoping it works for v.2!!! wub.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:50PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month