Delete Rows Based on Value

Big_Chew

New Member
Joined
Oct 15, 2020
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi again,

I am needing to delete rows if a cell contains a 0 or is a empty cell. I have some code that partially works but stops two rows short of the top. Any idea why? Below is a snippit of the data set and the code I am using. I am so very new to this.

1602856318951.png

VBA Code:
'Deletes Zero Linear Foot of Advance Rows
  Dim lastRow As Long
  Dim ws As Worksheet
  Set ws = Worksheets("Adjusted")
  lastRow = ws.Cells(ws.Rows.Count, 6).End(xlUp).Row
  For i = lastRow To 6 Step -1
 
  If ws.Cells(i, 6).Value = 0 Or ws.Cells(i, 6).Value = "0" Then
  ws.Cells(i, 6).EntireRow.Delete
  End If
  Next i
 

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.
You only have it going up to row 6:
VBA Code:
For i = lastRow To [B][COLOR=rgb(184, 49, 47)]6[/COLOR][/B] Step -1
Change that number "6" to the row number of the first row of data that you want to apply it to.
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,709
Members
449,118
Latest member
MichealRed

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