+ Reply to Thread
Results 1 to 3 of 3

VBA Code to run on selection of drop down menu

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2007
    Posts
    80

    VBA Code to run on selection of drop down menu

    Hi all,

    Here's what I have:
    A worksheet where, in most cells of column A, I have a data validation drop down menu where the options are "delete" or (blank). There is various data in three columns to the right of that.

    Here's what I need:
    A VBA code that will, on selection of "delete" from a drop down menu, come up with a box that says "Are you sure you wish to delete this row?" with the options 'yes' and 'no', and then delete that entire row if the user clicks 'yes', and if they click 'no' all it does is change the selection back to (blank).

    This is maybe a really easy one but I just can't quite get it right!

    Thanks for your help!
    Last edited by lealea1982; 02-23-2012 at 06:52 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: VBA Code to run on selection of drop down menu

    
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        On Error GoTo ws_exit
        
        Application.EnableEvents = False
        
        If Not Intersect(Target, Me.Range("E2:E200")) Is Nothing Then
        
            If Target.Value = "delete" Then
            
                If MsgBox("Are you sure that you want to delete this row", vbYesNo, "Delete Row") = vbYes Then
                
                    Target.EntireRow.Delete
                Else
                
                    Target.ClearContents
                End If
            End If
        End If
    
    ws_exit:
        Application.EnableEvents = True
    End Sub

  3. #3
    Registered User
    Join Date
    10-23-2007
    Posts
    80

    Re: VBA Code to run on selection of drop down menu

    Brilliant, thank you! I love this site!

+ 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