+ Reply to Thread
Results 1 to 4 of 4

Determining weather a macro will run or not

  1. #1
    Registered User
    Join Date
    09-30-2005
    Posts
    2

    Question Determining weather a macro will run or not

    Hi – I am looking for some help
    I would like to base weather a macro runs or not based on the day for the week.
    I have a button for each day of the week that an operator would push to complete some tasks. I want to avoid the potential of the operator pushing the wrong button – (I.e. the wrong day).
    I was thinking of using =today() and =weekday() functions in worksheet somewhere to test against. So that when the macro starts, I could test the =weekday() against a hard coded value on the macro.
    For example:
    If Windows("spreadsheet.xls").Activate
    Range("A!").Select = 4 – (where 4 is equal to =weekday() )
    Then – run the macro ….
    Else – do nothing – or maybe an error message box – telling the operator to choose the right button

    Any help !??!?!?!?

  2. #2
    Bernie Deitrick
    Guest

    Re: Determining weather a macro will run or not

    richiek,

    You should write your _single_ macro code to run based on the weekday, not have separate code for
    each weekday.

    Post your code, and somebody will help....

    HTH,
    Bernie
    MS Excel MVP


    "richiek" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi - I am looking for some help
    > I would like to base weather a macro runs or not based on the day for
    > the week.
    > I have a button for each day of the week that an operator would push to
    > complete some tasks. I want to avoid the potential of the operator
    > pushing the wrong button - (I.e. the wrong day).
    > I was thinking of using =today() and =weekday() functions in worksheet
    > somewhere to test against. So that when the macro starts, I could test
    > the =weekday() against a hard coded value on the macro.
    > For example:
    > If Windows("spreadsheet.xls").Activate
    > Range("A!").Select = 4 - (where 4 is equal to =weekday() )
    > Then - run the macro ..
    > Else - do nothing - or maybe an error message box - telling the
    > operator to choose the right button
    > Any help !??!?!?!?
    >
    >
    > --
    > richiek
    > ------------------------------------------------------------------------
    > richiek's Profile: http://www.excelforum.com/member.php...o&userid=27697
    > View this thread: http://www.excelforum.com/showthread...hreadid=472131
    >




  3. #3
    K Dales
    Guest

    RE: Determining weather a macro will run or not

    Your idea is OK, but you don't need to use the worksheet functions, do it all
    from within the macro, e.g:
    Sub Button1_Click() ' For Monday
    If Weekday(Date,1)=2 Then
    ... put code for Monday here
    End If
    End Sub

    Do you really need separate buttons, though? Why not one button and have
    your macro automatically run the appropriate code for the day it is?

    Sub MasterButton_Click()
    Select Case Weekday(Date,1)
    Case 1 ' Sunday
    ... code for Sunday
    Case 2 ' Monday
    ... code for Monday
    Case 3 ' Tuesday
    ... code for Tuesday
    etc. for other days up to:
    Case 7 ' Saturday
    ... code for Saturday
    End Select
    End Sub
    --
    - K Dales


    "richiek" wrote:

    >
    > Hi – I am looking for some help
    > I would like to base weather a macro runs or not based on the day for
    > the week.
    > I have a button for each day of the week that an operator would push to
    > complete some tasks. I want to avoid the potential of the operator
    > pushing the wrong button – (I.e. the wrong day).
    > I was thinking of using =today() and =weekday() functions in worksheet
    > somewhere to test against. So that when the macro starts, I could test
    > the =weekday() against a hard coded value on the macro.
    > For example:
    > If Windows("spreadsheet.xls").Activate
    > Range("A!").Select = 4 – (where 4 is equal to =weekday() )
    > Then – run the macro ….
    > Else – do nothing – or maybe an error message box – telling the
    > operator to choose the right button
    > Any help !??!?!?!?
    >
    >
    > --
    > richiek
    > ------------------------------------------------------------------------
    > richiek's Profile: http://www.excelforum.com/member.php...o&userid=27697
    > View this thread: http://www.excelforum.com/showthread...hreadid=472131
    >
    >


  4. #4
    Registered User
    Join Date
    09-30-2005
    Posts
    2

    Case worked !

    Hi K Dales

    I am not a programmer by trade – but have had some experience in the past.
    I was able to do what I needed to by using the Case statement.
    Works Great so far !!!
    Thank you VERY much for pointing me in the right direction!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1