Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Working with date and time (2000)

    Hi all,

    I am trying to enable a toolbar commandbutton after 2pm on the first day of the month. The code I have enables the button after 2 pm on the first day of the month, however, before 2 pm on the second and subsequent days, it is disabled. Any suggestions on structuring this so that after 2 pm on the first day of the month the button is enabled regardless of the time on the second and subsequent days?

    Here is what I have:

    <pre>If Date > ThisWorkbook.Sheets("Salesrecord").Range("ap7").Va lue</pre>

    <pre> And Time > TimeSerial(14, 0, 0) Then Abar11.Enabled = True</pre>


    Where Range("ap7") contains the date I am checking against and "Abar11" is the commandbutton I am trying to enable.
    Thanks

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Working with date and time (2000)

    If I understand what you want to do correctly, then something like this should work:

    <pre> If Day(Worksheets("Sheet1").Range("AP7").Value) = 1 And Hour(Worksheets("Sheet1").Range("AP7").Value) >= 14 Then
    Abar11.Enable = True
    End If
    </pre>

    Legare Coleman

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Working with date and time (2000)

    At first Legare, I thought that was it, but it still does a similar thing. I guess a better way of describing it would be not to enable the button before 2pm on the first day of the month, but to enable it on all subsequent days regardless of the time.

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Working with date and time (2000)

    Hi Michael,
    How about:
    If Date = ThisWorkbook.Sheets("Salesrecord").Range("ap7").Va lue

    And Time < TimeSerial(14, 0, 0) Then Abar11.Enabled = False
    I'm assuming that the date in ap7 is the date of the first of the month? Alternatively if you entered the first day of the month into cell ap7 and included the time of 2pm, you could use
    If Now > Range("AP7") Then Abar11.Enabled = True
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Working with date and time (2000)

    Michael,

    Would a slight alteration to Legare's formula help :<pre> If Day(Worksheets("Sheet1").Range("AP7").Value) = 1 _
    And Hour(Worksheets("Sheet1").Range("AP7").Value) < 14 Then
    Abar11.Enable = False
    Else
    Abar11.Enable = True
    End If</pre>

    I think that should leave the button enabled except before 2.00pm on the first of the month.
    Is that what you mean ?

    Andrew C

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Working with date and time (2000)

    Ok, I misunderstood what you are trying to do. Andrew's modification to my code should fix it for you.
    Legare Coleman

  7. #7
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Working with date and time (2000)

    Thanks all, just got home from work and haven't tried yet, but I'm sure that it will work now. Did not think about using the Now statement, that might be a simpler solution due to some other factors.

    Thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •