Using VBA to delete two rows based on value

robertdseals

Active Member
Joined
May 14, 2008
Messages
334
Office Version
  1. 2010
Platform
  1. Windows
Hello,
I'm using this to delete a row based on if a cell has a value of zero. However, I would like to delete the row with the value of zero and the row under it also.
Sub DeleteZeroRow()
'Updateby20140616
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Do
Set Rng = WorkRng.Find("0", LookIn:=xlValues)
If Not Rng Is Nothing Then
Rng.EntireRow.Delete
'Rows(ActiveCell.Row).Delete
End If
Loop While Not Rng Is Nothing
Application.ScreenUpdating = True
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
try adding this line of code

Code:
Rng.Offset(1,0).EntireRow.Delete
below
Code:
Rng.EntireRow.Delete
 
Upvote 0
Humm...that didn't seem to work. Stepping through the VBA that step doesn't seem to do anything. Maybe because the cell isn't "active"?
 
Upvote 0
Not sure that "active" is the issue as you have named a specific range (Rng) and you are deleting the Rng. Suggest that try putting the line of code I provided above instead of below your line of code.
 
Upvote 0

Forum statistics

Threads
1,214,854
Messages
6,121,941
Members
449,056
Latest member
denissimo

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