+ Reply to Thread
Results 1 to 8 of 8

Executing a macro based on worksheet change

  1. #1
    Registered User
    Join Date
    12-11-2007
    Posts
    15

    Executing a macro based on worksheet change

    Hello all,

    I currently have the following Macro --- it basically is looking at a session low price and increasing it by .0001 until it is equal to the session high. Here is the code:
    Please Login or Register  to view this content.
    What I want to do is stack a worksheet change event on top of this so that when the session low changes, the sheet dynamically updates the prices too. I don't know much VBA so I don't know how to write something else to call this. I saw examples of the worksheet change event, and I tried to implement them but I was unsuccessful. I tried this but I dont know the syntax or if I have to put this before my other macro on Sheet 1, in a separate module, etc (again, no VBA experience):
    Please Login or Register  to view this content.
    Not sure how to call my macro and how to stack these. Anyone have any ideas?

    Last caveat I forgot to put is that D3 is actually a formula, not a static number, so I think I am not using the right sub.
    Last edited by Leith Ross; 03-04-2010 at 01:19 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Executing a macro based on worksheet change

    Hello Rynofasho,

    I realize it has been awhile since you have posted. I have added code tags to your post as a courtesy this time, but please do so in the future. You should read the forum rules as there have been changes made to them.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-11-2007
    Posts
    15

    Re: Executing a macro based on worksheet change

    Quote Originally Posted by Leith Ross View Post
    Hello Rynofasho,

    I realize it has been awhile since you have posted. I have added code tags to your post as a courtesy this time, but please do so in the future. You should read the forum rules as there have been changes made to them.
    Will do in the future. Thank you!

  4. #4
    Registered User
    Join Date
    12-11-2007
    Posts
    15

    Re: Executing a macro based on worksheet change

    Anybody know?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Executing a macro based on worksheet change

    Click GO ADVANCED and use the paperclip icon to post up your workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    12-11-2007
    Posts
    15

    Re: Executing a macro based on worksheet change

    Here is the slightly changed sheet. Basically I want a worksheet change event to re-execute my macro every time the session high or session low changes (G2 and G3).

    Also, for my Volume at price calc using an IF and SUMIF, is there a 'cleaner' way to do that in VBA? I don't really mind my solution as it keeps the sheet aesthetically pleasing and it populates within a second or two. Just curious mostly.
    Attached Files Attached Files

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Executing a macro based on worksheet change

    Hello Rynofasho,

    Since the data appears to be imported by a web query, the Worksheet_Change() event will not fire when the cells are updated. A different method would need to be used to call the macro. To do that would require your original workbook.

    In the meantime, here is a VBA macro that fill in column "G" based on the high and low session values, sum all the entries in the "Trade" data, and the output those sums next to the corresponding value in column "H". This has been added to the attached workbook and can be run by clicking the button on the worksheet.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-11-2007
    Posts
    15

    Re: Executing a macro based on worksheet change

    Leith, thank you so much for the example. I appreciate it greatly. As far as my original workbook is concerned, there are no external weblinks. I am monitoring the session high and low via inhouse datafeed, and I can set up a function that will automatically update them if they change. The formula is not dynamic, so the actual results of the function (session high and low) are just numbers.

    The data on the left can be completely disregarded as it is just tick data that was already there. Does this alter my ability to use the worksheet change event? I apologize in advance for being rather VBA illiterate. I ordered that VBA power programming book from Walkenbach but it hasn't arrived so I haven't really been able to dive into it.

    Would you happen to have any examples of a worksheet change? And how do you "stack" the macros to where you can use one to call another? Is it necessary to create one as a module?

+ 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