Delete row Content specific

manoj_arsul

Board Regular
Joined
Jun 27, 2018
Messages
61
I have the below program for delete row if specific value content in column . but it getting too much time for running .

I want to run the same program but take less time.

Also help me for the run that program for different sheet (Sheet2)



Sub DeleteRowContents()

last = Cells(Rows.Count, "G").End(xlUp).Row
For i = last To 1 Step -1
If (Cells(i, "G").Value) = "ABCD" Then
Cells(i, "A").EntireRow.Delete
End If
Next i
For i = last To 1 Step -1
If (Cells(i, "G").Value) = "XYZ" Then
' Cells(i, "A").EntireRow.Delete
End If
Next i
For i = last To 1 Step -1
If (Cells(i, "G").Value) = "PQR" Then
Cells(i, "A").EntireRow.Delete
End If

Next i

End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this:
Code:
Sub Filter_Me_OK()
'Modified 7/4718 6:40 AM EDT
Dim Lastrow As Long
Dim c As Long
Dim Counter As Long
c = 7 ' Column Number Modify this to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row

With ActiveSheet.Cells(1, c).Resize(Lastrow)
    .AutoFilter Field:=1, Criteria1:=Array("ABCD", "XYZ", "PQR"), Operator:=xlFilterValues
    Counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If Counter > 1 Then
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
End Sub

Run this script on the sheet with your data
 
Last edited:
Upvote 0
Try this:
Code:
Sub Filter_Me_OK()
'Modified 7/4718 6:40 AM EDT
Dim Lastrow As Long
Dim c As Long
Dim Counter As Long
c = 7 ' Column Number Modify this to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row

With ActiveSheet.Cells(1, c).Resize(Lastrow)
    .AutoFilter Field:=1, Criteria1:=Array("ABCD", "XYZ", "PQR"), Operator:=xlFilterValues
    Counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If Counter > 1 Then
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
End Sub

Run this script on the sheet with your data

@My Aswer Is This : Thank you !! Its working for me .

Can you please send me program for the below condition .

in the same column ( Column - G) delete the rows if string is having words like below ( Delete all the rows content ABCD , XYZ, PQR )
1 . sadsd ABCD addwqewq
2 ewdewe PQR adadadsd
3 . XYZ wdeweq eewwqeq safd
4 . wewqe ERASD EWQE xyz
5. PQR ewer sewe

 
Upvote 0
I provided the answer to the question you asked.
The request you have now is:
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
in the same column ( Column - G) delete the rows if string is having words like below ( Delete all the rows content ABCD , XYZ, PQR )
1 . sadsd ABCD addwqewq
2 ewdewe PQR adadadsd
3 . XYZ wdeweq eewwqeq safd
4 . wewqe ERASD EWQE xyz
5. PQR ewer sewe


manoj_arsul,

It is always easier to help and test possible solutions if we could work with your actual file.

Perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com.

Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here.

Include a detailed explanation of what you would like to do referring to specific cells and worksheets.

If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
Try this on active sheet:
Code:
'Modified 7/7/18 10:10 AM EDT
Dim Lastrow As Long
Dim c As Long
Dim Counter As Long
c = 7 ' Column Number Modify this to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row
Dim Del As Variant
Del = Array("ABCD", "XYZ", "PQR")
ans = UBound(Del)
    For i = 1 To ans + 1
    
        With ActiveSheet.Cells(1, c).Resize(Lastrow)
            .AutoFilter 1, "*" & Del(i - 1) & "*"
            Counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
            If Counter > 1 Then
                .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            Else
                MsgBox "No values found"
            End If
                .AutoFilter
        End With
    Next
End Sub
 
Upvote 0
Since you can pass an array of values to filter for as part of the criteria, you can avoid looping and execute in single pass. As alt suggestion, try:
Code:
Sub Macro1()

Dim x                 As Long
Dim ColToFilter As Long

Application.ScreenUpdating = False

With ActiveSheet
    If .AutoFilterMode Then .AutoFilterMode = Fals
    
    ColToFilter = 7 'Adjust for whatever column index number you wish to filter
    
    x = .Cells(.Rows.Count, ColToFilter).End(xlUp).Row

    With .Cells(1, ColToFilter).Resize(x)
        .AutoFilter field:=1, Criteria1:=Array("ABC", "DEF", "XYZ"), Operator:=xlFilterValues
        On Error Resume Next
       .Offset(1).Resize(x - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
       On Error GoTo 0
    End With

End With

Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,066
Messages
6,128,582
Members
449,459
Latest member
20rayallen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top