+ Reply to Thread
Results 1 to 5 of 5

Delete a row if a cell contains a specific value

Hybrid View

  1. #1
    Registered User
    Join Date
    04-20-2008
    Posts
    33

    Delete a row if a cell contains a specific value

    Hi,
    I have a worksheet that contains 18 columns and a variable number of rows. I need to be able, at the push of a button, delete rows, only if they contain a specific value (in this case, 'cancelled' in Q:Q). I have several other command buttons linked to macros in this sheet, but do not have any idea where to start with the code for this application.
    Any help greatly appreciated.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi BLRITCHIE,

    The simple, maybe not the most elegant way, would be to loop through all of the used cells in column Q, and delete those rows where 'cancelled' appears. The following macro attached to a command button should work:
    Private Sub CommandButton1_Click()
        Dim i As Long
        For i = [Q65536].End(xlUp).Row To 2 Step -1
            If UCase(Cells(i, 17).Value) = "CANCELLED" Then
                Cells(i, 17).EntireRow.Delete Shift:=xlUp
            End If
        Next i
    End Sub

  3. #3
    Registered User
    Join Date
    04-20-2008
    Posts
    33

    wow - that was quick!

    Thanks - I didn't expect a reply so quickly.
    Have used the code you supplied and works a treat - bit clunky as you said but does exactly what I need. Thanks again.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    To stop the screen from twitching while the macro runs, you could add
    Application.ScreenUpdating = False
    at the beginning, and set it back to True at the end.

  5. #5
    Registered User
    Join Date
    04-20-2008
    Posts
    33

    very smoothe - thanks again.

    I've added this to some of the other existing functions on the sheet and the whole thing looks a lot better now. Cheers.

+ 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