+ Reply to Thread
Results 1 to 6 of 6

How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

  1. #1
    Forum Contributor
    Join Date
    12-11-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    308

    How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

    Apologies for A1>0 above. It should be if cell value [A1] > 00:00:15 ( ie 15 seconds). How to write a code so that a macro called "Mega" runs only once if cell value A1 > 00:00:15 ( time ), EVEN THOUGH the cell value (A1)remains increasing after that. The macro called "Mega" will also reset the value of cell A1 to zero which will start increasing with time but the macro ( Mega ) should not run for the second time. Please see the attached file. Once the macro "Mega" runs once and resets the cell A1 will start increasing with time but next time when it crosses 15 seconds, it should not trigger by itself( ie by the code which we write( ideally a simple code like

    Private Sub Worksheet_Calculate()

    If [A1] > Time(0,0,15) Then
    Mega
    End If
    End Sub

    ......will run it , but then there is nothing to stop it from running again. What can we do to change this code so that Mega may run only once ?
    Attached Files Attached Files
    Last edited by omega0010; 08-30-2014 at 09:24 AM. Reason: to simplify

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,591

    Re: How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    12-11-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    308

    Re: How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

    Thanks for your help. Unfortunately the code does not work alone or in combination ( I tried to put it with the code below because I need to run them together). I have put it in the main sheet code.
    Strangely usually I am using this code given below successfully with many steps and macros elswhere( just one of them being below)-

    Private Sub Worksheet_Calculate()

    If [A1] > Time(0,0,15) Then
    Mega
    End If
    End Sub

    How can we ad your code to the code above ? ( or can it run separately from a module ?)
    Actually while this simple code gives accurate and smooth run with many variables and steps (macros) elsewhere , in this particular sheet it gives me a prompt saying "Run time error" Type mismatch ..why ? Then how does this code run with many macros elsewhere ? Kindly throw some light on this subject. Thanx
    Omega0010
    Last edited by omega0010; 08-31-2014 at 02:32 AM. Reason: Grammatical mistakes changing the meaning

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,591

    Re: How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

    In Sheet1 module:

    Please Login or Register  to view this content.

    In standard/normal module:

    Please Login or Register  to view this content.

    See the updated example

    Regards, TMS

    Edit: trying to make thread appear in lists (second attempt)
    Attached Files Attached Files
    Last edited by TMS; 08-31-2014 at 06:01 AM. Reason: trying to make thread appear in lists

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,591

    Re: How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

    No new content: Edit: trying to make thread appear in lists (third attempt)

  6. #6
    Forum Contributor
    Join Date
    12-11-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    308

    Re: How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

    Thanks a lot TMS.
    I really appreciate your help.What appears to me is that nothing is happening despite the sophisticated programming done by you( which is far from my understanding of course!). I mean , I feel that from the opening of the file the program remembers that the macro was run at some time prior to opening time because when i try to trigger it by changing any different cell value the the time appears to be changing but nothing happens. Like how do we test that the program i.e. Mega has run once ?
    Thanks always to keep teaching people like me and helping the helpless!

  7. #7
    Forum Contributor
    Join Date
    12-11-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    308

    Re: How to write a code so that a macro called "Mega" runs only once if cell value A1 > 0

    Yes I have checked it and it actually works as immediately as the book opens where as actually my idea was to open the book at around 9 am computer time and run mega at 9:15 for once could you please give a direction as to what change to do ?

+ 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. Code only runs when a user hits "Save", not "Save As"
    By cjstewart8 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2014, 07:41 PM
  2. Trying to Write a Macro to SaveAs Cell "P3" in a Permanent Folder
    By jtal in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-04-2013, 08:09 PM
  3. [SOLVED] how code do i need to write before "RANGE("A1").value to access a specific worksheet?
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2013, 03:46 AM
  4. Code for button runs and causes "1004" error on Exit and Save
    By TreePapa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2010, 02:02 PM
  5. Macro that runs entered value through "low" and "high" range
    By Vika.F in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2005, 03:35 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