+ Reply to Thread
Results 1 to 3 of 3

Delete Unwanted Rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Delete Unwanted Rows

    On the attached example I want to add some code to the Command Button that when pressed deletes the rows where column J has the text "No Shops".

    Any ideas on how to write the code?

    Cheers.
    Attached Files Attached Files

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Delete Unwanted Rows

    Here you go

     Dim ptr As Long, LastRow As Long
     
     LastRow = Cells(Rows.CountLarge, "j").End(xlUp).Row
     
     With Application
        .ScreenUpdating = False
        For ptr = LastRow To 2 Step -1
           If Cells(ptr, "j") = "No Shops" Then
               Cells(ptr, "j").EntireRow.Delete
           End If
        Next
        .ScreenUpdating = True
     End With
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Contributor
    Join Date
    08-23-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Delete Unwanted Rows

    Try the below code...
    Private Sub CommandButton1_Click()
    n = Range("J65536").End(xlUp).Row
    For i = 1 To n
        If Cells(i, 10).Value = "No Shops" Then
            Cells(i, 10).EntireRow.Delete
            i = i - 1
        End If
    Next i
    End Sub
    Last edited by JBeaucaire; 09-14-2012 at 10:33 AM.

+ 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