Consulting

Results 1 to 6 of 6

Thread: Sleeper: Trigger event when rows are inserted or deleted

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Sleeper: Trigger event when rows are inserted or deleted

    Hi All
    Is there a way to run a macro only when rows are inserted or deleted?
    MD

  2. #2
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi MD,

    The only way that I can think of at the moment is this - replace Excel's built-in menu options for Insert and Delete with your own routines that perform the Insert and Delete and also do whatever it is that you want to do.

    I haven't actually tried this - just thinking out loud!

  3. #3
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Given what Richie had suggested, try this link.
    http://www.andrewsexceltips.com/tips.htm

    Look for June 05 blog

  4. #4
    VBAX Contributor
    Joined
    Dec 2004
    Posts
    122
    Location
    I believe I got this code from this site once. Place this in a worksheet module.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Target.EntireRow.Address Then
    MsgBox "REMINDER! after DELETING row press button 1"
    End If
    End Sub
    Last edited by Aussiebear; 04-14-2023 at 04:21 PM. Reason: Adjusted the code tags

  5. #5
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by gsouza
    I believe I got this code from this sight once. Place this in a worksheet module.

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = Target.EntireRow.Address Then
            MsgBox "REMINDER! after DELETING row press button 1"
        End If
    End Sub
    This will work for Delete, but not for Insert. For reasons not clear to me, Insertion is not considered a "change".

    I had a similar need a few years ago where I wanted to control how/what could be inserted or deleted; users were deleting only portions of rows and columns and messing up the formulas in other areas. Controling delete was pretty easy (using Worksheet_Change) but controling Insert was not. I eventually did something along the lines of what Richie suggests, i.e., wrote substitute routines that were dynamically substituted for the standard routines when the particular application was started. Worked OK.
    Last edited by Aussiebear; 04-14-2023 at 04:22 PM. Reason: Adjusted the code tags
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks all.
    I'll give these a try
    MD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •