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
 
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
VoG did provide you with new edited code, you just are reading it too fast to see to see the difference... he removed the "dots" in front of the Range property calls. Try copy/pasting his new code into your module and you will see it reacts differently when executed.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This of course is not to ammend the previous faux pas I made. Here's code which should work:
Code:
Public Sub UpdateRange()
Dim i As Integer
Application.ScreenUpdating = False
For i = 100 To 1 Step -1
    If Range("F" & i).Value = "" Or UCase(Range("E" & i).Value2) = "TOTAL" Then
    Rows(i).Delete
    End If
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I will again post my code I posted earlier, maybe you have overlooked my contribution, but in any case it is working and more efficient than the other suggestions (which are easier to understand but that should not be a criterion):

Code:
Sub Delete_Rows()
    With [A1:H100].Columns(5)
        .Replace "TOTAL", "", xlWhole
        .Resize(, 2).SpecialCells(4).EntireRow.Delete
    End With
End Sub
 
Upvote 0
First of all Thanks from the bottom of my heart to all of you guys, u guys r doing great job . sorry for feedback as i m doing job, now i m back to home from office.
@ VoG i m really sorry, i was too fast to read ur new edited code and did try that again as it was morning here and i had to go for office so i just read it , sorry again, ur new edited code is working but is not providing me the expected result, i really appreciate for ur time, interest and hard work. Thanks.
@Rick_RothSein Thanks for pointing out my mistake

@taurean ur given code is working perfectly fine and thanks for providing me this code, i appreciate for ur hard work and time.

@wigi i tried ur code too and it is giving me the expected result and it is perfectly fine. Thanks for ur contribution too, i appreciate it.

i have been given so many codes to solve my problem, which code i will follow ?
the code given by njimack is working perfectly fine, i selected code given by
njimack just bcoz that, i m understanding this code very well as compare to others and i can this code according to my need, for example, i can put more criteria etc and i amended that code by putting more criteria n got success, i tried to understand code of others but failed to do so as i m new into this
http://www.mrexcel.com/forum/member.php?u=17822
 
Upvote 0
Now the only problem i m having, the below code is just limited to one sheet only, each time, i will need to write sheet name in this code.
i want this code to work on all workbooks and on all excel files, So please kindly amend this below code according to my need. Thank you very much



Code:
Sub Delete_Rows() Dim i As Long Application.ScreenUpdating = False With Sheets("Sheet1")     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</pre>
 
Upvote 0
Just make this change

Rich (BB code):
Sub Delete_Rows()
Dim i As Long
Application.ScreenUpdating = False
With ActiveSheet
    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
@VoG Thanks for amending it, it is working great, now i don't need to put sheet name again n again but still one problem is there, i have saved this code in my excel workbook but when i open another excel workbook file, i don't get this code there, that code is saved only for that particular workbook, and i don't want to put this code again n again on my each excel workbook and save it manually, i want to apply this code on any workbook excel file without doing it manually, how can i do this or there is need to change something in code ?
 
Upvote 0
Put the code in the Personal macro workbook. Then it's accessible to all opened workbooks.
 
Upvote 0

Forum statistics

Threads
1,225,149
Messages
6,183,188
Members
453,151
Latest member
Lizamaison

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