Help with Case Code

rkol297

Board Regular
Joined
Nov 12, 2010
Messages
131
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a spreadsheet that in Column E there are therapy type abreviations and in Column I there are numbers that end in - # (example 5965859-0 or 5965895-8 or 598654-5) I need to have code that first looks at the abreviations in Column E and on one tab named "IG MEDCO SETUPS" I need to keep all rows that contain any of the following "ARAL", "BERT", "GLSA", "ZEMA" and on another tab called "PAH MEDCO SETUPS" I need to keep all values that contain these abreviations in Column E </SPAN>"EPAC", "EPAP", "EPOP", "FL50", "F100", "REMO", "REMP", "RMIP", "RMIV", "VENP", "VENT" now for all other abreviations in column E that are not outlined above I want to keep only those rows that end in "-0" in Column I.

Here is the case code that I have attempted to do this with but for some reason it is not doing what I want:
Code:
'###REMOVES ALL ITEMS EXCEPT VARIABLE FILLS BASED ON THERAPY TYPE IN COLUMN E AND 0 FILLS FOR ALL THERAPIES ON IG MEDCO TAB###</SPAN>
    Sheets("IG MEDCO SETUPS").Select</SPAN>
    Dim CelIGMEDCO0F As Range, RngIGMEDCO0F As Range, iIGMEDCO0F As Long</SPAN>
    Set RngIGMEDCO0F = Columns("I").SpecialCells(xlConstants, xlTextValues)</SPAN>
    For iIGMEDCO0F = RngIGMEDCO0F.Count To 2 Step -1</SPAN>
        Select Case UCase(Trim(Range("E" & iIGMEDCO0F).Value))</SPAN>
            Case "ARAL", "BERT", "GLSA", "ZEMA"</SPAN>
                'do nothing</SPAN>
            Case Else</SPAN>
                If Right(Range("I" & iIGMEDCO0F).Value, 2) <> "-0" _</SPAN>
                Then Rows(iIGMEDCO0F).Delete</SPAN>
            End Select</SPAN>
    Next iIGMEDCO0F</SPAN>
 
'###REMOVES ALL ITEMS EXCEPT VARIABLE FILLS BASED ON THERAPY TYPE IN COLUMN E AND 0 FILLS FOR ALL THERAPIES FOR PAH MEDCO TAB###</SPAN>
    Sheets("PAH MEDCO SETUPS").Select</SPAN>
    Dim CelPAHMEDCO0F As Range, RngPAHMEDCO0F As Range, iPAHMEDCO0F As Long</SPAN>
    Set RngPAHMEDCO0F = Columns("I").SpecialCells(xlConstants, xlTextValues)</SPAN>
    For iPAHMEDCO0F = RngPAHMEDCO0F.Count To 2 Step -1</SPAN>
        Select Case UCase(Trim(Range("E" & iPAHMEDCO0F).Value))</SPAN>
            Case "EPAC", "EPAP", "EPOP", "FL50", "F100", "REMO", "REMP", "RMIP", "RMIV", "VENP", "VENT"</SPAN>
                'do nothing</SPAN>
            Case Else</SPAN>
                If Right(Range("I" & iPAHMEDCO0F).Value, 2) <> "-0" _</SPAN>
                Then Rows(iPAHMEDCO0F).Delete</SPAN>
            End Select</SPAN>
    Next iPAHMEDCO0F</SPAN>
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
My first guess is that the ranges you are getting are not what you think they are.

In the debugger, see what the value of "RngIGMEDCO0F.count" is.

There are a number of ways that you can find the last row in the sheet. Check out some of the other posts (People tell me the way I do it is not reliable so I won't post it for you)
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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