+ Reply to Thread
Results 1 to 19 of 19

Start a macro when a cell value changes from 2 to 1.

  1. #1
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Start a macro when a cell value changes from 2 to 1.

    Please check the spreadsheet , have explained everything there.

    thnx
    Attached Files Attached Files
    Last edited by Sarangsood; 08-26-2013 at 04:10 AM.

  2. #2
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    sorry the spreadsheet wasn't opening the wright sheet when downloaded. it will now. thnx

  3. #3
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Start a macro when a cell value changes from 2 to 1.

    place below in the code section of the Trng Rate sheet.
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved , to mark your thread as Solved select Thread Tools and click Mark thread as Solved.

    I can't read the mind of my wife so then I get picture but no sound .... and then I mostly get the idea, same goes here picture your outcome and I get the idea.

  4. #4
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    when the value comes to 1 , its not really executing the macro but only the message box is appearing.

  5. #5
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    also there are 4 macros which need to be executed automatically when the value of there related cell changes to 1 as shown in the attachment.
    Last edited by Sarangsood; 08-26-2013 at 05:16 AM.

  6. #6
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Start a macro when a cell value changes from 2 to 1.

    updated your file and replaced the message box with the actual call

  7. #7
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    sir you have almost done it. the problem now is that there is a formula in j23,j24,j26,j28. its not responding to the formula only if i manually enter 1, then it
    responds. this is my actual sheet. thnx a ton
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    sir you have almost done it. the problem now is that there is a formula in j23,j24,j26,j28. its not responding to the formula only if i manually enter 1, then it
    responds. this is my actual sheet. thnx a ton
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Start a macro when a cell value changes from 2 to 1.

    is joke right ?
    if i knew that from start it was way easier

    put below in the code section of the Trng Rate sheet
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    oops sorry my bad

    okay i pasted the exact code. but my sheet freezes now ??

  11. #11
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Start a macro when a cell value changes from 2 to 1.

    works fine here , please make sure you remove all previous code under the Trng Rate sheet

  12. #12
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    this is what i have done .try to type c in e23 , it hangs the whole sheet.
    Attached Files Attached Files

  13. #13
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Start a macro when a cell value changes from 2 to 1.

    @hulpeloos - since he said "Please note the data is realtime. So the data in J23:J27 will change automatically.", I assume the data change that trigger the target cells changes are not on the same sheet (cause other sheets are referenced) -- A worksheet change event won't work then. Anyway - even if worksheet change would work, don't forget to add in Application.EnableEvents = False so it won't loop forever (which I suspect is happening now.

    @Sarangsood - if the changes are actually caused by changes on other worksheets then the only way to go about it is to test for data changes for example every second and then run the macros accordingly.
    Can you confirm that the changes are induced from other worksheets. If not, hulpeloos' code should work, just add

    Please Login or Register  to view this content.
    as first line after "Private Sub Worksheet_Change"
    and add
    Please Login or Register  to view this content.
    as last line just before "End Sub"
    Please click the * below if this helps

  14. #14
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Start a macro when a cell value changes from 2 to 1.

    By the way, here's how I would do it.

    Appoint one cell to be the "on / off" cell - in the example below, I took "P1". As long as there's a 1 in cell P1, the code will keep running and keep checking. As soon as you change that to anything else, the code will stop.
    This will check the cells J23:J27 every second.

    Put this code in your worksheet code area
    Please Login or Register  to view this content.
    Put this code in a module
    Please Login or Register  to view this content.
    Please click the * below if this helps

  15. #15
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    yes sir. the cells e23:e27 are from another sheet. first two from "aug" and the last two from "sep". the cells e23:e27 are the original one's which when changed should trigger the subsequent macros.
    you can check the if formula in k23:k27 to understand better.

  16. #16
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Start a macro when a cell value changes from 2 to 1.

    In that case, my solution should work, no?

  17. #17
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    did exactly what you said. now type "c" in e23 , it should change the value in j23 to 1. but the macro isn't executing??
    Attached Files Attached Files

  18. #18
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Start a macro when a cell value changes from 2 to 1.

    It's cause I made a typo, sorry.
    Change the module code as below :

    Please Login or Register  to view this content.
    Also, when you open the workbook, you need to enter "1" into P1 again to first start the macro. If you want to auto-start it, add this in your workbook code section :

    Please Login or Register  to view this content.
    Please remember to click the * below if this helps

  19. #19
    Forum Contributor
    Join Date
    05-18-2011
    Location
    Delhi , India
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Start a macro when a cell value changes from 2 to 1.

    wow works perfectly. thanks a lot

    haven't tried it out with real time data because my office is closed for the day. but will surely let you know if something goes wrong

    again appreciate it very much.

+ 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. How to start Macro if a cell = Yes
    By ConfusedaboutVBA in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2013, 09:49 PM
  2. Macro to start if cell value is between 0.001 and - 0.001
    By Hjahren in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-07-2010, 02:48 AM
  3. Start Macro on cell update
    By CJ-22 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-21-2006, 08:08 AM
  4. Start macro on cell input
    By CJ-22 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2006, 02:17 AM
  5. Can I start a macro from a cell by using a formula
    By PraxisPete in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-08-2005, 05:28 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