Hiding rows in a cell is blank

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have some code that is meant to look at the bottom 8 rows in a spreadsheet and if column D has a 0 or nothing in that cell for each row, it is meant to hide the row. What is wrong with the code I wrote as it won't work?


Sub SecondNMore()
Dim cell As Range, n As Long, e As Long, f As Long, i As Long
e = Range("D" & Rows.Count).End(xlUp).Row
'f = Range("D56").End(xlDown).Row
For Each cell In Range("D" & e - 8 & ":D" & e)
If cell.Value = "" Or cell.Value = 0 Then Rows(e).Hidden = True
e = e - 1
Next cell
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try
VBA Code:
Sub SecondNMore()
Dim e As Long, r As Long
e = Range("D" & Rows.Count).End(xlUp).Row
For r = e To e - 8 Step -1
If Range("D" & r).Value = "" Or Range("D" & r).Value = 0 Then Rows(r).EntireRow.Hidden = True
Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,236
Messages
6,123,799
Members
449,127
Latest member
Cyko

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