+ Reply to Thread
Results 1 to 5 of 5

Disable code during certain times and Run another.

  1. #1
    Forum Contributor
    Join Date
    03-12-2014
    Location
    Riyadh
    MS-Off Ver
    Office 365
    Posts
    129

    Disable code during certain times and Run another.

    Hello friends! hope all is well!

    Need your kind and amazing help please.

    The workbook here has a looping code that goes from one sheet to the other every 5 seconds. All is well here.

    I want to disable the code from 1-1:15PM AND 3-3:15PM AND 6-6:15PM.

    I want to call a VBA code name RefreshDataBase instead.


    Please help & Thank you very much in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Disable code during certain times and Run another.

    This might work

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    03-12-2014
    Location
    Riyadh
    MS-Off Ver
    Office 365
    Posts
    129

    Re: Disable code during certain times and Run another.

    Very cool! Thank you. One last question,

    Let us instead run the code every hour.
    Can we RefreshDataBase with the following code? i.e. is the code below correct? if not please help.

    much appreciated!


    Please Login or Register  to view this content.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Disable code during certain times and Run another.

    I don't believe that would run the RefreshDataBase at all. Off hand I can't think of how to tell it to only run RefreshDataBase every hour in your set up, but if I do, I will post back.
    Last edited by JLGWhiz; 06-12-2019 at 08:32 AM.

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Disable code during certain times and Run another.

    I did not test this, but it seems logical. I used Range("A1") as the storage range, but you can change that in both places to a range that will not interfere with your data. The throry is that When the my macro runs, it will check cell A1 (or the cell you choose) to determine if one hour has lapsed since the last RefreshDataBase and if it has then it will run the macro and put a new time in the storage cell and skips the rest of MyMacro. If one hour has not elapsed, then it runs the rest of MyMacro. You will need to put a starting time in the storage cell to kick it off. After that the code will update the cell. The part I am not sure about is the "1:00:00" but you can test it and see what happens.

    Please Login or Register  to view this content.
    Last edited by JLGWhiz; 06-12-2019 at 01:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Disable Insert button code works fine, but some times throws Run-Time error '5'
    By challasl in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-18-2016, 05:41 AM
  2. Replies: 9
    Last Post: 04-17-2016, 07:34 PM
  3. Replies: 21
    Last Post: 03-04-2015, 07:19 PM
  4. VB code to disable cut/paste
    By Pigmy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2014, 04:58 AM
  5. error on disable/insert row disable code
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2014, 05:15 AM
  6. If a search term can be found 1 time, 2 times 3 times 4 times 5 times
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 09:57 PM
  7. Disable Macros From Within VBA Code?
    By Eric S. in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2007, 10:36 AM

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