Results 1 to 4 of 4

Macro to delete row within a specified range or disallow if out of range

Threaded View

Mayweed Macro to delete row within a... 04-06-2011, 10:37 AM
jwright650 Re: Macro to delete row... 04-06-2011, 10:41 AM
Mayweed Re: Macro to delete row... 04-06-2011, 10:44 AM
Mayweed Re: Macro to delete row... 04-07-2011, 01:50 PM
  1. #4
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Smile Re: Macro to delete row within a specified range or disallow if out of range

    If I totally deny reading a post by shg concerning ws selectionChange events on another forum, I can honestly say that I've solved this one myself!

    The only caveat that I'm aware of; if using this code on a protected worksheet, then cell B1 must be unlocked.
    If it helps anyone, I've attached a workbook.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim myrange As Range
        On Error Resume Next
        Set myrange = Intersect(Range("A2:C20"), Target)
        If Not myrange Is Nothing Then
             Range("B1") = "True"
             Else
             Range("B1") = "False"
        End If
    End Sub
    
    
    Sub DelRowProtected()
    ActiveSheet.Unprotect Password:=""
    If Range("B1") = "True" Then
    ActiveCell.EntireRow.Delete
    Else
    MsgBox "Select a cell in the range A2 to C20 to delete the row"
    End If
    ActiveSheet.Protect Password:=""
    End Sub
    Attached Files Attached Files

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