+ Reply to Thread
Results 1 to 7 of 7

Cell value change runs a macro?

  1. #1
    Registered User
    Join Date
    01-07-2006
    Posts
    26

    Cell value change runs a macro?

    Is there a way to make it so that if a cell value changes, a macro is called?

  2. #2
    Nick Hodge
    Guest

    Re: Cell value change runs a macro?

    Sure

    You use a Worksheet_Change() event. To access this press alt+f11 to access
    the VBE, right click on the worksheet concerned and select view code... In
    the left drop-down in the resulting window select worksheet and in the right
    one select Change. You will get a template as below. Now the rub... you
    have to be able to write VBA code to do anything with it. (Obviously you
    could record some and cut and paste it between the Private Sub...End Sub
    lines, but eventually you will need to hand write some for sure)

    Private Sub Worksheet_Change(ByVal Target As Range)

    End Sub

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    www.nickhodge.co.uk
    [email protected]HIS


    "Steach91" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Is there a way to make it so that if a cell value changes, a macro is
    > called?
    >
    >
    > --
    > Steach91
    > ------------------------------------------------------------------------
    > Steach91's Profile:
    > http://www.excelforum.com/member.php...o&userid=30234
    > View this thread: http://www.excelforum.com/showthread...hreadid=553053
    >




  3. #3
    L. Howard Kittle
    Guest

    Re: Cell value change runs a macro?


    From Worksheet Object Events help.
    Example
    This example changes the color of changed cells to blue.

    Private Sub Worksheet_Change(ByVal Target as Range)
    Target.Font.ColorIndex = 5
    End SubHTH
    Regards,
    Howard

    "Steach91" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Is there a way to make it so that if a cell value changes, a macro is
    > called?
    >
    >
    > --
    > Steach91
    > ------------------------------------------------------------------------
    > Steach91's Profile:
    > http://www.excelforum.com/member.php...o&userid=30234
    > View this thread: http://www.excelforum.com/showthread...hreadid=553053
    >




  4. #4
    Registered User
    Join Date
    01-07-2006
    Posts
    26

    Amended Question

    Thanks for the prompt replies... As seems to always be the case, I probably made a broad question too broad..

    I'm looking for a way to run a macro if cell (L16)'s value changes. Not the whole worksheet.

    Again, thanks for the help!

  5. #5
    Arvi Laanemets
    Guest

    Re: Cell value change runs a macro?

    Hi

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 12 And Target.Row = 16 Then
    ' Add your code here
    MsgBox "There was a change in cell L16"
    End If
    End Sub



    Arvi Laanemets

    "Steach91" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Thanks for the prompt replies... As seems to always be the case, I
    > probably made a broad question too broad..
    >
    > I'm looking for a way to run a macro if cell (L16)'s value changes. Not
    > the whole worksheet.
    >
    > Again, thanks for the help!
    >
    >
    > --
    > Steach91
    > ------------------------------------------------------------------------
    > Steach91's Profile:

    http://www.excelforum.com/member.php...o&userid=30234
    > View this thread: http://www.excelforum.com/showthread...hreadid=553053
    >




  6. #6
    Registered User
    Join Date
    01-07-2006
    Posts
    26

    That did the trick!

    Thank you very much for the help!

  7. #7
    Nick Hodge
    Guest

    Re: Cell value change runs a macro?

    Worksheet_Change monitors all cells, you just need to tell it which one,
    like this

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("L16")) Is Nothing Then
    OtherMacro
    End If
    End Sub

    This will run a macro called OtherMacro if cell L16 is changed.

    Now you need to beware if the macro makes other changes to the worksheet or
    else you code will be called each time it is. You can prevent this by
    adding

    Application.EnableEvents=False

    but remember to turn them back on at any place where code can exit
    (including errors) or you will be left with no events at all in Excel

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    www.nickhodge.co.uk
    [email protected]HIS


    "Steach91" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Thanks for the prompt replies... As seems to always be the case, I
    > probably made a broad question too broad..
    >
    > I'm looking for a way to run a macro if cell (L16)'s value changes. Not
    > the whole worksheet.
    >
    > Again, thanks for the help!
    >
    >
    > --
    > Steach91
    > ------------------------------------------------------------------------
    > Steach91's Profile:
    > http://www.excelforum.com/member.php...o&userid=30234
    > View this thread: http://www.excelforum.com/showthread...hreadid=553053
    >




+ 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