Results 1 to 8 of 8

Executing a macro based on worksheet change

Threaded View

  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:
    Sub increment()
    
    Range("E8:E5000").ClearContents
    
    i = 1
    j = 0
    
    Do Until Range("D4").Value = Range("E7").Offset(j, 0).Value
        Range("E7").Offset(i, 0).Value = Range("E7").Offset(j, 0).Value + 0.0001
    
    j = j + 1
    i = i + 1
    Loop
    
    End Sub
    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):
    Private Sub Worksheet_Change(ByVal Target As Range) 
    
    If Target.Address = "$D$3" Then 
    
    Call increment
    
    End If 
    
    End Sub
    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

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