+ Reply to Thread
Results 1 to 6 of 6

Run Macro on Change

  1. #1
    Ken Hudson
    Guest

    Run Macro on Change

    I have the following code in Sheet1. When I change data in cell D5, it
    invokes the FindInv macro. If I then try to clear a range of cells in Sheet1,
    say D3:D4, the code below runs again and I get a type mismatch error. What do
    I need to do to prevent this?

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target = Range("D5") Then FindInv
    End Sub


    Thanks.
    --
    Ken Hudson

  2. #2
    Jim Thomlinson
    Guest

    RE: Run Macro on Change

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.address = "$D$5" Then FindInv
    End Sub
    --
    HTH...

    Jim Thomlinson


    "Ken Hudson" wrote:

    > I have the following code in Sheet1. When I change data in cell D5, it
    > invokes the FindInv macro. If I then try to clear a range of cells in Sheet1,
    > say D3:D4, the code below runs again and I get a type mismatch error. What do
    > I need to do to prevent this?
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > If Target = Range("D5") Then FindInv
    > End Sub
    >
    >
    > Thanks.
    > --
    > Ken Hudson


  3. #3
    Ken Hudson
    Guest

    RE: Run Macro on Change

    Thanks, Jim.
    This is my first foray into this type of VBA code. I'm moving from plain
    vanilla to vanilla swirl.....
    --
    Ken Hudson


    "Jim Thomlinson" wrote:

    > Private Sub Worksheet_Change(ByVal Target As Range)
    > If Target.address = "$D$5" Then FindInv
    > End Sub
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "Ken Hudson" wrote:
    >
    > > I have the following code in Sheet1. When I change data in cell D5, it
    > > invokes the FindInv macro. If I then try to clear a range of cells in Sheet1,
    > > say D3:D4, the code below runs again and I get a type mismatch error. What do
    > > I need to do to prevent this?
    > >
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > If Target = Range("D5") Then FindInv
    > > End Sub
    > >
    > >
    > > Thanks.
    > > --
    > > Ken Hudson


  4. #4
    Jim Thomlinson
    Guest

    RE: Run Macro on Change

    Stick around... Tom might give out his recipe for Chocolate... I'm still
    waiting... :-)
    --
    HTH...

    Jim Thomlinson


    "Ken Hudson" wrote:

    > Thanks, Jim.
    > This is my first foray into this type of VBA code. I'm moving from plain
    > vanilla to vanilla swirl.....
    > --
    > Ken Hudson
    >
    >
    > "Jim Thomlinson" wrote:
    >
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > If Target.address = "$D$5" Then FindInv
    > > End Sub
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Ken Hudson" wrote:
    > >
    > > > I have the following code in Sheet1. When I change data in cell D5, it
    > > > invokes the FindInv macro. If I then try to clear a range of cells in Sheet1,
    > > > say D3:D4, the code below runs again and I get a type mismatch error. What do
    > > > I need to do to prevent this?
    > > >
    > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > If Target = Range("D5") Then FindInv
    > > > End Sub
    > > >
    > > >
    > > > Thanks.
    > > > --
    > > > Ken Hudson


  5. #5
    Tom Ogilvy
    Guest

    RE: Run Macro on Change

    Jim,
    Maybe you can make it chocolate by telling him what his first attempt was
    actually checking for.

    --
    Regards,
    Tom Ogilvy


    "Jim Thomlinson" wrote:

    > Stick around... Tom might give out his recipe for Chocolate... I'm still
    > waiting... :-)
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "Ken Hudson" wrote:
    >
    > > Thanks, Jim.
    > > This is my first foray into this type of VBA code. I'm moving from plain
    > > vanilla to vanilla swirl.....
    > > --
    > > Ken Hudson
    > >
    > >
    > > "Jim Thomlinson" wrote:
    > >
    > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > If Target.address = "$D$5" Then FindInv
    > > > End Sub
    > > > --
    > > > HTH...
    > > >
    > > > Jim Thomlinson
    > > >
    > > >
    > > > "Ken Hudson" wrote:
    > > >
    > > > > I have the following code in Sheet1. When I change data in cell D5, it
    > > > > invokes the FindInv macro. If I then try to clear a range of cells in Sheet1,
    > > > > say D3:D4, the code below runs again and I get a type mismatch error. What do
    > > > > I need to do to prevent this?
    > > > >
    > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > If Target = Range("D5") Then FindInv
    > > > > End Sub
    > > > >
    > > > >
    > > > > Thanks.
    > > > > --
    > > > > Ken Hudson


  6. #6
    Jim Thomlinson
    Guest

    RE: Run Macro on Change

    I bet your chocolate tastes better but here goes...

    The default property of a range such as Target or Range("D5") is the value
    of the range, so the macro would run not only when D5 was changed, but
    whenever the cell that was changed had a value equal to the value in D5...
    What we need to check in this case is the address of the cell that was
    changed, so by checking the address of the target (returns a string) against
    "$D$5" we will know when cell D5 changed...

    One day Tom I will be half the chef you are and then we will all be in
    trouble... :-)
    --
    HTH...

    Jim Thomlinson


    "Tom Ogilvy" wrote:

    > Jim,
    > Maybe you can make it chocolate by telling him what his first attempt was
    > actually checking for.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Jim Thomlinson" wrote:
    >
    > > Stick around... Tom might give out his recipe for Chocolate... I'm still
    > > waiting... :-)
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Ken Hudson" wrote:
    > >
    > > > Thanks, Jim.
    > > > This is my first foray into this type of VBA code. I'm moving from plain
    > > > vanilla to vanilla swirl.....
    > > > --
    > > > Ken Hudson
    > > >
    > > >
    > > > "Jim Thomlinson" wrote:
    > > >
    > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > If Target.address = "$D$5" Then FindInv
    > > > > End Sub
    > > > > --
    > > > > HTH...
    > > > >
    > > > > Jim Thomlinson
    > > > >
    > > > >
    > > > > "Ken Hudson" wrote:
    > > > >
    > > > > > I have the following code in Sheet1. When I change data in cell D5, it
    > > > > > invokes the FindInv macro. If I then try to clear a range of cells in Sheet1,
    > > > > > say D3:D4, the code below runs again and I get a type mismatch error. What do
    > > > > > I need to do to prevent this?
    > > > > >
    > > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > > If Target = Range("D5") Then FindInv
    > > > > > End Sub
    > > > > >
    > > > > >
    > > > > > Thanks.
    > > > > > --
    > > > > > Ken Hudson


+ 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