+ Reply to Thread
Results 1 to 16 of 16

Need macro help restricting when it is executed

Hybrid View

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

    Re: Need macro help restricting when it is executed

    Why then, check for changes in A20 instead of changes in Range("A1:A19") ?

    Put the range so you check the cells that are actually (manually) changed, instead of a calculated result and you should be set.
    If *all* the cells you want to check are calculated results and none are manually changed, it's a bit more of a challenge, but then you could solve it by using a helper cell.
    For example, you want a macro to fire when A20 changes, but A20 is calculated from cell changes on another sheet - how to go about it?
    I'd do something like this :

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("Z1000").Value = "" Then Range("Z1000").Value = Range("A20").Value
    If Range("A20").Value = Range("Z1000").Value Then Goto nexxt
    Range("Z1000").Value = Range("A20").Value
    'your code here
    nexxt:
    How does that work?
    If cell Z1000 is empty, then the value in cell A20 is put in it ; From that moment on, cell Z1000 has the same value as cell A20, which is checked on _every_ change of the worksheet.
    If cell A20 value somehow changes, then A20 value is different from Z1000 value and your code will run.

    Hope this makes sense.

  2. #2
    Registered User
    Join Date
    05-07-2013
    Location
    Carlisle
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Need macro help restricting when it is executed

    Clever stuff this! Bit beyond me but I'll be impressed if i can get it working!

    Right then that code above seems to work when cells are changed on the same sheet as A20 and Z1000 but A20 might change due to a cell being changed on another sheet and then i might not change another cell on the same sheet as A20 so the check does not run and therefore my code does not run.

    My problem is (and to give you a feel of what i am trying to achieve), i enter data on sheets 1,2,3 and 4 which then pull through onto sheet 5 and amount to a total for each person. So on sheet 5 i have say 20 columns for 20 different people which pulls data from sheets 1-4.

    When the total at the bottom of each persons column is changed i want it to fire the macro for that persons sheet (after sheet 5 i have another 20 sheets, 1 for each person).

    If you could revise the above code to work for this scenario then i will be forever grateful

    Many many thanks for your help on this...

+ 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