Using VBA to delete two rows based on value

robertdseals

Active Member
Joined
May 14, 2008
Messages
327
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

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.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
7,483
Office Version
  1. 365
Platform
  1. Windows
try adding this line of code

Code:
Rng.Offset(1,0).EntireRow.Delete
below
Code:
Rng.EntireRow.Delete
 
Upvote 0

robertdseals

Active Member
Joined
May 14, 2008
Messages
327
Office Version
  1. 2010
Platform
  1. Windows
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

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
7,483
Office Version
  1. 365
Platform
  1. Windows
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,191,183
Messages
5,985,170
Members
439,944
Latest member
Vangelis74

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
Top