It won't skip rows because there are two "counters".
LastRowNum is the last row number. The macro will check that many rows.
ReadRow is the row being checked. It only increases by one when the row doesn't meet the criteria (under the Else bit of the macro. Where one of the criteria are met and the row is deleted, ReadRow isn't changed, and the same row number is checked again. So if row 10 is deleted, row 11 becomes row 10 and row 10 is checked again.
Here is another macro that you can consider (add any new items to the comma delimited quoted list that I show in blue below)...
I am sorry, I misread one of your previous messages to say you want the search to be case sensitive, but now I see you wanted case insensitive. Here is the revision (only one thing needed to be changed... one True to a False)...Not sure why but when I tried your code it deleted all the rows containing "%", but none containing resistor or any of the other categories.
Sub DelColH()
Dim V As Variant, DeleteMe As Variant
DeleteMe = Array("%", "Resistor", "Capacitor", "MCKT", "Connector")
For Each V In DeleteMe
Columns("H").Replace "*" & V & "*", "#N/A", xlWhole, ,False, False, False
Next
On Error Resume Next
Columns("H").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
End Sub
What if I wanna start from H4 in column "H" what changes should be made in this code!I'm assuming that you're looking for exact matches (i.e. not the specified word in the middle of a sentence)? If so, try this macro, adding any extra lines you need where marked:
Code:Sub DelColH() LastRowNum = Cells.SpecialCells(xlCellTypeLastCell).Row ReadRow = 1 For n = 1 to LastRowNum If Range("H" & ReadRow).Value = "%" Or _ Range("H" & ReadRow).Value = "Resistor" Or _ Range("H" & ReadRow).Value = "Capacitor" Or _ Range("H" & ReadRow).Value = "MCKT" Or _ 'Add similar lines here for anything else that you want to delete. Last line must end with Then, not Or _. Range("H" & ReadRow).Value = "Connector" Then Range("H" & ReadRow).EntireRow.Delete Else ReadRow = ReadRow + 1 End If Next End Sub
I think you just need to change the range you are applying it to.What if I wanna start from H4 in column "H" what changes should be made in this code!
Sub DelColH()
Dim V As Variant, DeleteMe As Variant, lr As Long
lr = Cells(Rows.Count, "H").End(xlUp).Row
DeleteMe = Array("%", "Resistor", "Capacitor", "MCKT", "Connector")
For Each V In DeleteMe
Range("H4:H" & lr).Replace "*" & V & "*", "#N/A", xlWhole, , False, False, False
Next
On Error Resume Next
Range("H4:H" & lr).SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
End Sub
ReadRow = 1
For n = 1 to LastRowNum
ReadRow = 4
For n = 4 to LastRowNum
Hi Thx for reply!What if I wanna start from H4 in column "H" what changes should be made in this code!
I did check n = 4 it skips 4 rows which I wanna delete!Zshanar69 - in my code that you quoted, you just need to change the 1 in the ReadRow... and For... lines to the row number of the first cell. So for H4:
becomes:Code:ReadRow = 1 For n = 1 to LastRowNum
Code:ReadRow = 4 For n = 4 to LastRowNum