Delete row where specific cell is blank or meets condition

hip2b2

Board Regular
Joined
May 5, 2003
Messages
135
Office Version
  1. 2019
Platform
  1. Windows
I have seen any number of macros that delete a blank row. What I am looking for is a macro that will delete a row when a specific condition is met on that roe, i.e. cell in column XX is blank, value in specific cell = x, etc.

Any suggestions?

Thanks

hip
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Re: Delete row where specific cell is blank or meets conditi

does this mean you want to be checking for multiple values in the rows for deletion?? I can probably provide some code, but I'm not exactly sure what it is you've got in mind.
 
Upvote 0
Re: Delete row where specific cell is blank or meets conditi

No, only looking for one condition to be met, ( most likley the if cel in col B, the delete row).

Thanks

hip
 
Upvote 0
Re: Delete row where specific cell is blank or meets conditi

Here's probably someting simmilar to what you want:

Code:
Sub myDeleteRows()

Dim MyCol As String
Dim MyVal As Variant
Dim i As Integer

MyCol = InputBox("column to look through", "Column Search", "A")
MyVal = InputBox("Value to look for", "search value", 0)
  For i = 1 To Range(MyCol & "65536").End(xlUp).Row Step 1
    If Application.WorksheetFunction.CountIf(Range("A" & i & ":AZ" & i), MyVal) > 0 Then
    Range("A" & i).EntireRow.Delete
    End If
  Next i
  
End Sub
 
Upvote 0
Re: Delete row where specific cell is blank or meets conditi

I would prefer something simpler, where I enter the column and variable in the macro itself. Unfortunatly, I can't quite seem to rearrange your macro to do this for me.

Many thanks


hip :pray:
 
Upvote 0
Re: Delete row where specific cell is blank or meets conditi

Another possinle solution:

You can delete an entire row based on the value in a particular column or range using something like this

Sub Deleteit()
Dim c As Range
For Each c In Selection
If c.Value = Range("$B$1").Value Then c.EntireRow.Delete
Next
End Sub

Select the column (Say Col A) and run this macro.
If the value of a cell in Column A = $B$1, then the entire row will be deleted
 
Upvote 0
Re: Delete row where specific cell is blank or meets conditi

I used the code below, however it only deletes a row if the value is exactly what I enter when inputting a value for MyVal. Here's what I'm dealing with:

I have 10,000 emails in one column. I need to delete a row if part of the email's string is generic (ie: "yahoo.com", "gmail.com", etc...). I believe this can be done with the code below, as it works if the string is exactly the same as what's inputted when running the macro; however, I don't care what comes before the generic email provider. Any ideas?

Here's probably someting simmilar to what you want:

Code:
Sub myDeleteRows()

Dim MyCol As String
Dim MyVal As Variant
Dim i As Integer

MyCol = InputBox("column to look through", "Column Search", "A")
MyVal = InputBox("Value to look for", "search value", 0)
  For i = 1 To Range(MyCol & "65536").End(xlUp).Row Step 1
    If Application.WorksheetFunction.CountIf(Range("A" & i & ":AZ" & i), MyVal) > 0 Then
    Range("A" & i).EntireRow.Delete
    End If
  Next i
  
End Sub
 
Upvote 0
Re: Delete row where specific cell is blank or meets conditi

Hello - is it possible to use this macro on a defined column range instead of the whole column? The way it seems to run is for the whole entire column even though my test has 10 rows of data. THX

Sub Deleteit()
Dim c As Range
For Each c In Selection
If c.Value = Range("$B$1").Value Then c.EntireRow.Delete
Next
End Sub
 
Upvote 0
Hi Guys,

Learnt a lot from this thread but as other learners I need some more help.
I am using the code below to delete rows based on an empty cell in column K

Range("K:K").SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.delete
Range("A1").Select 'Get back to top of Sheet

The code above works perfect to delete the rows based on all the column.

Not sure how to modify this code but I don't want the code to start looking at the rows until it gets to K8, which is the first row under the headers.
I also need to duplicate the code to then look in column C (again from C8) and delete the rows if the 8 digit number begins with a 1.

Thanks in advance.

Craig.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

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