Deleting Rows with Certain Values in VBA

tanney9

New Member
Joined
Apr 8, 2009
Messages
8
I'm running into an issue when I try to generate a report for the largest five values in a report. Some of the cells have a zero divisor in their formula so they come up with the #DIV/0 error. I've put in an If statement to make those equal 0, but the LARGE formula still returns #NAME?. Any ideas on how to get the LARGE formula to work.

I would like to be able to delete the rows with zero in the reference column, so their data is not even in the report. Does anyone know how to do this in VBA?:confused:
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this to delete rows where J is 0

Code:
Sub DelJ0()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("J" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("J" & i)
        If .Value = 0 Then .EntireRow.Delete
    End With
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Maybe someone can help with this again. I've copied the command above to another macro. This time instead on looking at column J, I want to delete if column E is zero. I made the changes from J to E. But I'm getting a Compile error: Expected End Sub.

Prior to this in the macro. I'm copying and pasting the values to get rid of formulas. Any help would be greatly appreciated.
 
Upvote 0
Sub TESE_B35()
'
' TESE_B35 Macro
' Macro recorded 7/1/2009 by Michael Smith
'

'
Sheets("Chase").Select
Application.Run "BLPLinkReset"
Rows("6:6").Select
Selection.Copy
Rows("7:7").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Cells.Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Paste
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False


Sub DelE0()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("E" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
With Range("E" & i)
If .Value = 0 Then .EntireRow.Delete
End With
Next i
Application.ScreenUpdating = True




Dim filename As String
filename = "T:\QSG\TESE\Trade Reports\TESEChase_ExecutionReport_" + Format(Now(), "yyyymmdd")
ActiveWorkbook.SaveAs filename, xlNormal

End Sub
 
Upvote 0
You need to delete this line from the middle of the code

Sub DelE0()
 
Upvote 0
Error went away, but did not delete any of the rows.

Check that I made an input error. Thanks for the help AGAIN.
 
Upvote 0

Forum statistics

Threads
1,215,499
Messages
6,125,163
Members
449,210
Latest member
grifaz

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