Delete Rows based on condition

iffi

Board Regular
Joined
Jun 5, 2011
Messages
59
Office Version
  1. 2019
Platform
  1. Windows
All of you have been so kind to help others in solving their problems including me. we all appreciate it.
once again i need ur help, here it is my problem

for example within this range from A1 to H100, i want to delete every row which is blank cell in the column of F whithin the above specified range and i also want to delete every row which contains this Text "Total" in the column of E within the above specified range.

i think this is not possible with any formulae, right ? So plz suggest and provide me Easy solution for this one, such as any type of Code or macro, or any other which u think is better and easy for this.
Thank you very very much. Please i need this solution as soon as possible. Thanks again
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try

Code:
Sub DeleteRows()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If .Range("E" & i).Value Like "*Total*" Or .Range("F" & i).Value = "" Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
You could do this manually using autofilter. For an automated approach, something like:

Code:
Sub Delete_Rows()
Dim i As Long
Application.ScreenUpdating = False
With Sheets("Sheet1") 'amend sheetname as appropriate
    For i = 100 To 1 Step -1
        If .Cells(i, 6) = "" Or .Cells(i, 5) = "TOTAL" Then .Cells(i, 1).EntireRow.Delete
    Next i
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks to both VoG and njimack and sorry for late feedback.

code given by VoG is giving error of complile error invalid or unqualified reference, i have no idea whether i m doing some mistake or there is problem in that code.

Code given by njimack is working fine but this code is also deleting all the rows where there is Total in cell of Column E above the specified range of 100, i don't want to delete any row to be deleted above the specified range, plz limit this code within the specified range only and provide me that edited code again.
and i also could u plz explain me just one line within ur code which is " For i = 100 To 1 Step -1 " and also what does " i " mean in code ? i want to understand this line just bcoz so that i can change this code according to my need when i need to do that, i m understanding everything else in this code.

Thanks you very very much
 
Upvote 0
Thanks to both VoG and njimack and sorry for late feedback.

code given by VoG is giving error of complile error invalid or unqualified reference, i have no idea whether i m doing some mistake or there is problem in that code.

Code given by njimack is working fine but this code is also deleting all the rows where there is Total in cell of Column E above the specified range of 100, i don't want to delete any row to be deleted above the specified range, plz limit this code within the specified range only and provide me that edited code again.
and i also could u plz explain me just one line within ur code which is " For i = 100 To 1 Step -1 " and also what does " i " mean in code ? i want to understand this line just bcoz so that i can change this code according to my need when i need to do that, i m understanding everything else in this code.

Thanks you very very much
This might prove a stupid post. But I will accept the hazard :)! Have you considered the possibility that after rows deletion, rows 101 onwards will come inside row 100?

There is no reason why the macro should wander outside those 100.
 
Upvote 0
Hello

You should avoid loops in Excel if possible. For instance:

Code:
Sub Delete_Rows()
    With [A1:H100].Columns(5)
        .Replace "TOTAL", "", xlWhole
        .Resize(, 2).SpecialCells(4).EntireRow.Delete
    End With
End Sub
 
Upvote 0
Oops!

Code:
Sub DeleteRows()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If Range("E" & i).Value Like "*Total*" Or Range("F" & i).Value = "" Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
This might prove a stupid post. But I will accept the hazard :)! Have you considered the possibility that after rows deletion, rows 101 onwards will come inside row 100?

There is no reason why the macro should wander outside those 100.

before saying this post stupid, have you verified my saying by trying that code at ur side, whether i m wrong or right or this post is stupid ???
i have considered each n every possibility, i have even written Total in cell 110 in column E and that code deletes that entire row of 110 as well and i know that 101 will come inside row 100. thanks for ur time
 
Upvote 0
Oops!

Code:
Sub DeleteRows()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If Range("E" & i).Value Like "*Total*" Or Range("F" & i).Value = "" Then Rows(i).Delete
Next i
End Sub

i thought you provided me new edited code again but there is no change in it, maybe u r little busy for that. Thanks for ur time Sir
 
Upvote 0
before saying this post stupid, have you verified my saying by trying that code at ur side, whether i m wrong or right or this post is stupid ???
i have considered each n every possibility, i have even written Total in cell 110 in column E and that code deletes that entire row of 110 as well and i know that 101 will come inside row 100. thanks for ur time
My sincere apologies. I was referring to my OWN post and not yours. Sometimes we miss small things and the search becomes painful.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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