Code to delete rows (need help adjusting)

thewiseguy

Well-known Member
Joined
May 23, 2005
Messages
1,019
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

Here is my code to delete all rows with value "0" in column C.


Sub DeleteRowOnCell7()
For i = 450 To 1 Step -1
If Cells(i, "C").Value = "0" Then Rows(i).EntireRow.Delete
Next i
End Sub

At the end of all of my data. I have 2 rows worth of totals. The problem I am having is that once the code is run, there is a big gap between my data and my totals of all the data. Is there a way to get the totals (in rows 456 and 457) to move upward as the "0" value cells are deleted?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
Sub DeleteRowOnCell7() 
For i = 450 To 1 Step -1 
If Cells(i, 3).Value = "0" Then Rows(i).Delete Shift:= xlUp 
Next i 
End Sub
 
Upvote 0
Code:
Sub DeleteRowOnCell7() 
For i = 450 To 1 Step -1 
If Cells(i, 3).Value = "0" Then Rows(i).Delete Shift:= xlUp 
Next i 
End Sub

Hi,

I tried this code, but I am still having the same problem.
 
Upvote 0
Are you looking at a value zero or a text string “0”? If the former then try:
Code:
Sub DeleteRowOnCell7() 
For i = 450 To 1 Step -1 
If Cells(i, 3) = 0 Then Rows(i).Delete Shift:= xlUp 
Next i 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,804
Messages
6,181,056
Members
453,015
Latest member
ZochSteveo

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