Delete Rows

fari1

Active Member
Joined
May 29, 2011
Messages
362
hi, my below code is deleting the rows that contain the text defined in the code, while i want to delete the rows other than below text.
plz help

Code:
Sub filingsdelete()
    Dim wsInput As Worksheet
    Dim wsInputLRw As Long, i As Long
    Dim RngSource As Range
    Application.ScreenUpdating = False
    
    Set wsInput = Sheets("filings")
    
    wsInputLRw = wsInput.Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 2 To wsInputLRw
        Select Case UCase(wsInput.Range("A" & i).Value)
        Case "10-K", "10-Q", "10-K/A", "10-Q/A"
            If RngSource Is Nothing Then
                Set RngSource = wsInput.Range("A" & i)
            Else
                Set RngSource = Union(RngSource, wsInput.Range("A" & i))
            End If
        End Select
    Next i
    
    If Not RngSource Is Nothing Then _
    RngSource.EntireRow.Delete
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If I understand right..

It currently deletes rows that are 10-k or 10-Q or 10-K/A or 10-Q/A
right

and you want to change it to delete all OTHER rows instead..right?

Just put the relevant code in a Case Else line, and do nothing in the Original Case line..

Rich (BB code):
Sub filingsdelete()
    Dim wsInput As Worksheet
    Dim wsInputLRw As Long, i As Long
    Dim RngSource As Range
    Application.ScreenUpdating = False
    
    Set wsInput = Sheets("filings")
    
    wsInputLRw = wsInput.Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 2 To wsInputLRw
        Select Case UCase(wsInput.Range("A" & i).Value)
        Case "10-K", "10-Q", "10-K/A", "10-Q/A"
            'Do Nothing
        Case Else
            If RngSource Is Nothing Then
                Set RngSource = wsInput.Range("A" & i)
            Else
                Set RngSource = Union(RngSource, wsInput.Range("A" & i))
            End If
        End Select
    Next i
    
    If Not RngSource Is Nothing Then _
    RngSource.EntireRow.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,337
Members
452,907
Latest member
Roland Deschain

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