VBA Help

Miya

Well-known Member
Joined
Nov 29, 2008
Messages
662
Hi, this code deletes all the cases listed in the code, but how can i add another rule which will not delete SMPFFB?

Code:
Public Sub NomsPfolios()
Dim i As Long, _
LR As Long

LR = Range("B" & Rows.Count).End(xlUp).Row
ScreenOff
For i = LR To 7 Step -1
Select Case Left(Range("B" & i).Value, 2)
Case "WE", "WS", "WT", "WM"
Case Else
Rows(i).Delete
End Select
Next i
ScreenOn
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
First off, I'm assuming that you mistyped and that the code is intended to delete all rows EXCEPT the cases listed. (first two charaters are "WE", "WS", etc)

If so, this

Code:
Public Sub NomsPfolios()
    Dim i                           As Long, _
        LR As Long
    LR = Range("B" & Rows.Count).End(xlUp).Row
    ScreenOff
    For i = LR To 7 Step -1
        Select Case Left(Range("B" & i).Value, 2)
        Case "WE", "WS", "WT", "WM"
        Case Else
            'This could grow up to be a monster, but if it does you could 
            'switch to a nested select
            If Left(Range("B" & i).Value, 6) <> "SMPFFB" Then
                Rows(i).Delete
            End If
        End Select
    Next i
    ScreenOn
End Sub

should work.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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