+ Reply to Thread
Results 1 to 6 of 6

Delete a row based on user selection

  1. #1
    Registered User
    Join Date
    12-04-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    43

    Exclamation Delete a row based on user selection

    I want to delete the row if a user select "Reject It" from a drop down list. I coded it like this: Which is not working for me, please help

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ThisWorkbook.Activate
    Worksheets("AllDeps").Activate
    With Worksheets("AllDeps")
    Dim i As Integer
    For i = 2 To 19
    If .Range("M" & i) = "Reject it" Then
    Rows(i).EntireRow.Delete
    End If
    Next
    End With
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Delete a row based on user selection

    Quote Originally Posted by vivekchha View Post
    ...
    Please Login or Register  to view this content.
    Code tags are required when displaying code, please use them.

    Your code is in the worksheet module, there would be no reason to activate the workbook because you are already in the workbook, same goes for activating the sheet.

    Give this a try..... Put it in a regular module, see my signature if you don't know where the code goes.
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Delete a row based on user selection

    Try this as a sheet specific macro,

    Right click on the sheet name at the bottom of excel

    Paste this there.

    Delete your existing code.

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Delete a row based on user selection

    Hi mehmetcik,

    Would you not have to start at the bottom to delete rows in your loop?

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Delete a row based on user selection

    Hi Dave you are right it would be slightly faster to go from bottom to top.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-04-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Delete a row based on user selection

    Thanks all. I got it. In fact I put "Reject It" in drop down list whereas "Reject it" in codes.
    Some times so small mistakes take so much time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create a pop-up box with based on user selection
    By ohrytsay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2014, 07:42 PM
  2. Cell Selection based on user click
    By mohsinismail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2014, 12:28 PM
  3. [SOLVED] Macro to delete/mark criteria based on user selection
    By D_N_L in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-03-2014, 08:02 AM
  4. Replies: 1
    Last Post: 06-03-2013, 06:30 AM
  5. Dynamic Pie Chart Based on User Selection
    By mcollins789 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-03-2013, 06:17 PM

Tags for this Thread

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