Deleting rows in excel using VBA using column cell data criteria

eastbiomed

New Member
Joined
Jul 9, 2012
Messages
13
Thanks in advance! I have a excel 2010 spreadsheet that has a column "H". In column "H" many of the cells have the folowing data: "Department Open PM Count :" and in this same column "H" some of the cells directly above the cell data: "Department Open PM Count :" has a cell value of: "Call #" WhaT iw ould like to do is when this combination occurs, I would like to delete both rows. Here's a little sample:

COLUMN H
Call #
000123567
000485857
000344566
Department Open PM Count:

Call #
Department Open PM Count:

Call #
000123567
000485857
000344566
Department Open PM Count:



In my above example some areas of my column H have calls associated with them but in some there aren't any. When there are no call numbers listed, just the cell value Call# then immediately below is Department Open PM Count... I would like a VBA script that can recognize that combination and delete those two rows. This occurs frequently in column H.

Thanks again!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I think you need to try something like this :

Code:
Public Sub Remov_Empty_Call()
    Dim LastRow As Long: LastRow = Range("H" & Rows.Count).End(xlUp).Row
    
    Dim l As Long
    For l = 1 To LastRow
        If Range("H" & l).Value = "Call #" And Range("H" & l + 1).Value = "Department Open PM Count:" Then
            Range(l & ":" & l + 1).Delete shift:=xlShiftUp
            l = l - 1
            LastRow = LastRow - 2
        End If
    Next l
End Sub
 
Upvote 0
Thanks in advance! I have a excel 2010 spreadsheet that has a column "H". In column "H" many of the cells have the folowing data: "Department Open PM Count :" and in this same column "H" some of the cells directly above the cell data: "Department Open PM Count :" has a cell value of: "Call #" WhaT iw ould like to do is when this combination occurs, I would like to delete both rows. Here's a little sample:

COLUMN H
Call #
000123567
000485857
000344566
Department Open PM Count:

Call #
Department Open PM Count:

Call #
000123567
000485857
000344566
Department Open PM Count:



In my above example some areas of my column H have calls associated with them but in some there aren't any. When there are no call numbers listed, just the cell value Call# then immediately below is Department Open PM Count... I would like a VBA script that can recognize that combination and delete those two rows. This occurs frequently in column H.

Thanks again!

Your VBA script worked flawlessly! To make my report perfect I need one more script...

In column B after runnin gyour script I have this:

COLUMN B

Department: ICU
BEC#
6748994
48475686
958568609
Department: OR
BEC#
24536241
657848393
Department: RESP
Department: EKG
Bec#
756474843

In my above example, Department: Resp is not associated with any BEC equipment ID numbers. At times, in my report there are three departments in a row not associated with any BEC labels. Here's what I am looking for. In Column B I would like to delete any row where column B starts with Dep, except for the ones that have BEC# in the row below them. Thank you so much, I am getting better at this but not at your level yet!
 
Upvote 0
Your VBA script worked flawlessly! To make my report perfect I need one more script...

In column B after running your script I have this:

COLUMN B

Department: ICU
BEC#
6748994
48475686
958568609
Department: OR
BEC#
24536241
657848393
Department: RESP
Department: EKG
Bec#
756474843

In my above example, Department: Resp is not associated with any BEC equipment ID numbers. At times, in my report there are three departments in a row not associated with any BEC labels. Here's what I am looking for. In Column B I would like to delete any row where column B starts with Dep, except for the ones that have BEC# in the row below them. Thank you so much, I am getting better at this but not at your level yet!

*********************************************************
Solved my own question!!! I changed your script a bit and changed the equal sign to the term "like" and changed all the column H references to column B and the searched term changed to DEP* Yay for us!
 
Upvote 0

Forum statistics

Threads
1,214,381
Messages
6,119,192
Members
448,874
Latest member
Lancelots

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