For i .....next i

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Hi,

I want to delete row when my cells = 2
Code:
For i = 2 To a    
    If Cells(i, 15) = "2" Then Cells(i, 15).EntireRow.Delete
Next i

But when the row it's deleted macro is skipped one row.

How can I avoid the situation?
 
here is my all code:

Code:
MsgBox "Open files"
Application.Dialogs(xlDialogOpen).ShowDim WB As Workbook
Set WB = ActiveWorkbook
Dim WS As Worksheet
Set WS = WB.Sheets("Sheet1")
    
Dim a, i As Long
a = Application.WorksheetFunction.CountA(Columns(15))

For i = a To 2 Step -1
    
    If Cells(i, 15) = "2" Then Cells(i, 15).EntireRow.Delete
    
Next i

but doesn't work properly
 
Upvote 0
Also if you have any blank cells in column 15 between the last row and row 1 you will miss checking rows as the results of counta and cells(i,j) won't align.
 
Upvote 0

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