Remove Row in two columns in two ranges VBA

AccountantinExcel

New Member
Joined
Sep 10, 2018
Messages
10
I am trying to write a macro to remove rows with a cell value of zero in Range H4-H1003 and I1004-I2003.

Can anyone help with this?

Sub Remove_Empty_Cells()
Dim ws As Worksheet, last As Long, i As Long
For Each ws In Worksheets(Array("JE"))
ws.Activate
last = Cells(Rows.Count, "H1003").End(xlUp).Row 'Delete rows
For i = last To 3 Step -1
If Cells(i, "H1003").Value = 0 Then
Cells(i, "H4").EntireRow.Delete
End If
Next i
last = Cells(Rows.Count, "I2003").End(xlUp).Row 'Delete rows
For j = last To 3 Step -1
If Cells(i, "I2003").Value = 0 Then
Cells(i, "I1004").EntireRow.Delete
End If
Next j
Next ws
End Sub

Thanks!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub DeleteRowsWithZerosInColumnHandI()
  With Range("H1", Cells(Rows.Count, "H").End(xlUp))
    .Value = Evaluate("IF((" & .Address & "=0)*(" & .Offset(, 1).Address & "=0),""#N/A""," & .Address & ")")
    On Error GoTo NoDoubleZeros
    .SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
NoDoubleZeros:
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Give this macro a try...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub DeleteRowsWithZerosInColumnHandI()
  With Range("H1", Cells(Rows.Count, "H").End(xlUp))
    .Value = Evaluate("IF((" & .Address & "=0)*(" & .Offset(, 1).Address & "=0),""#N/A""," & .Address & ")")
    On Error GoTo NoDoubleZeros
    .SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
NoDoubleZeros:
End Sub[/TD]
[/TR]
</tbody>[/TABLE]


That worked Thanks!!
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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