Macro to delwete zero values

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have written code to delete all rows from row 8 onwards where there is a zero value in column 8, but cannot get it to work

Your assistance in resolving the matter is most appreciated

Sub Delete_Zero_Values()
finalrow = Cells(65536, 8).End(xlUp).Row
For i = finalrow To 8 Step -1
If Cells(i, 8).Value = "0" Then
Cells(i, 8).EntireRow.Delete
End If
Next i
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Which module is the code in?
It must be in the corresponding worksheet module in order for your code to work.
 
Upvote 0
Thanks for the reply. The macro is in the worksheet module. There are 30000 rows of data and it seems to be going into a loop. Is my code correct or does it need to be amended?
 
Upvote 0
Macro has finally run. I thought there was a problem, but due to +- 30000 rows it took +- 3 mins to run
 
Upvote 0
Deleting rows always take a long time.
there is a better algorithm but it requires sorting then deleting.
 
Upvote 0
The other reason could be there will be formulas which might be getting calculated every time a row is deleted.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

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