Remove all Rows that don't subtotal Zero

LoraKnight

New Member
Joined
Jun 18, 2013
Messages
14
How can I remove rows from my spreadsheet that don't subtotal Zero in the Subtotaled "CPT" Column. I only want to leave the group of data that has a subtotal of Zero in the "CPT" Column.

This is the complete Sheet
Practice Code
Appt Date
Pat Person Nbr
Pat First Name
Pat Last Name
Appt Status
CPT
Appt Status Desc
Reason Desc
Appt Provider Name
LKMN
1/2/2013
3241.1
A
Smith
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
3241.1
A
Smith
99213,TH
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
3241.1 Count
1
1
LKMN
1/2/2013
31064.3
B
Jones
T
Occurred
Post Op
Smith, Doctor
LKMN
1/2/2013
31064.3
B
Jones
Office Visit-Est Patient; Intermed
Smith, Doctor
31064.3 Count
1
0
LKMN
1/2/2013
40300
C
Johnson
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
40300
C
Johnson
99213,TH
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
40300 Count
1
1
LKMN
1/2/2013
49746.1
D
Williams
T
Occurred
Problem Check
Smith, Doctor
LKMN
1/2/2013
49746.1
D
Williams
99213
Office Visit-Est Patient; Intermed
Smith, Doctor
49746.1 Count
1
1
LKMN
1/2/2013
52680.3
E
Roberts
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
52680.3
E
Roberts
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
52680.3 Count
1
0
LKMN
1/2/2013
75595.1
F
Lard
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
75595.1
F
Lard
99213,TH
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
75595.1 Count
1
1
LKMN
1/2/2013
104405
G
Wilks
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
104405
G
Wilks
99213,TH
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
104405 Count
1
1
LKMN
1/2/2013
119088
J
Smith
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
119088
J
Smith
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
119088 Count
1
0
LKMN
1/2/2013
123931
K
Nolan
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
123931
K
Nolan
99213,TH
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
123931 Count
1
1
LKMN
1/2/2013
164819
L
Morris
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
164819
L
Morris
59400,X
Routine Obstetric Care Includi Ng a
Smith, Doctor
164819 Count
1
1

<TBODY>
</TBODY>


This is what I would like to be left with after the removal of the rows that don't subtotal Zero in the CPT Column





Practice Code
Appt Date
Pat Person Nbr
Pat First Name
Pat Last Name
Appt Status
CPT
Appt Status Desc
Reason Desc
Appt Provider Name
LKMN
1/2/2013
31064.3
B
Jones
T
Occurred
Post Op
Smith, Doctor
LKMN
1/2/2013
31064.3
B
Jones
Office Visit-Est Patient; Intermed
Smith, Doctor
31064.3 Count
1
0
LKMN
1/2/2013
52680.3
E
Roberts
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
52680.3
E
Roberts
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
52680.3 Count
1
0
LKMN
1/2/2013
119088
J
Smith
T
Occurred
Ob Visit
Smith, Doctor
LKMN
1/2/2013
119088
J
Smith
TH
Office Visit-Est Patient; Intermed
Smith, Doctor
119088 Count
1
0

<TBODY>
</TBODY>

<TBODY>
</TBODY>
 
Last edited:
This formula works great. Thank you.
Could you adjust it for me to remove all associated rows that have a subtotal of "1" in the CPT column?
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Code:
Sub RowsRemoval()

Dim i, j, thelastrow As Long

    thelastrow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
    
    For i = thelastrow To 1 Step -1
        If InStr(1, Cells(i, 3), "Count") <> 0 Then
            If Cells(i, 7).Value <> "0" Then
                For j = i To 1 Step -1
                    If Cells(j, 7).Value = "CPT" Then Exit Sub
                    If InStr(1, Cells(j, 3), "Count") <> 0 And i <> j Then
                    Exit For
                    Else
                    Rows(j).EntireRow.Delete
                    End If
                Next j
            End If
        End If
    Next i

End Sub


This formula works great. Thank you. Could you adjust it for me to remove all associated rows that have a subtotal of "1" in the CPT column?
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,971
Members
449,276
Latest member
surendra75

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