ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   hiding rows containing formulas which return zero values (https://www.excelbanter.com/excel-programming/416007-hiding-rows-containing-formulas-return-zero-values.html)

Roger on Excel

hiding rows containing formulas which return zero values
 
I use code to hide empty rows on a sheet. This works fine if the cells dont
have formulas in them and are empty.

However, if I use formulas in those rows which return blank cells, the code
doesnt hide the rows.

Even though the formulas in the cells return a zero value based upon
criteria, the rows wont hide.

Here is the code i use:

Dim rng As Range
On Error Resume Next
Range("a28:a54").EntireRow.Hidden = False
Set rng = Range("a28:a54").SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Hidden = True
End If


Can anyone suggest code which will hide the rows if the formulas in cells
a28 to a 54 return zero values?

Thanks,

Roger


JLGWhiz

hiding rows containing formulas which return zero values
 
If you use formulas in the cells, then they do not meet the xlBlank criteria
and will not hide, not matter that the value is zero. The cell is not blank,
it has a formula.
You will probably have to use a For Each statement and check for "" Or
..Value = 0.
Dim c As Range
For Each c In Range"A28:A54")
If c = "" Or c.Value = 0 Then
c.EntireRow.Hidden = True
End If
Next

"Roger on Excel" wrote:

I use code to hide empty rows on a sheet. This works fine if the cells dont
have formulas in them and are empty.

However, if I use formulas in those rows which return blank cells, the code
doesnt hide the rows.

Even though the formulas in the cells return a zero value based upon
criteria, the rows wont hide.

Here is the code i use:

Dim rng As Range
On Error Resume Next
Range("a28:a54").EntireRow.Hidden = False
Set rng = Range("a28:a54").SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Hidden = True
End If


Can anyone suggest code which will hide the rows if the formulas in cells
a28 to a 54 return zero values?

Thanks,

Roger


DMoney

hiding rows containing formulas which return zero values
 
Sub tst()

Range("a28").Select
For i = 1 To 50
If ActiveCell.Value = 0 Then
ActiveCell.EntireRow.Hidden = True
ActiveCell.Offset(1, 0).Activate
ElseIf ActiveCell.Value = "" Then
ActiveCell.EntireRow.Hidden = True
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Offset(1, 0).Activate
End If
Next i

End Sub


This is not pretty, but it gets the job done.

dmoney

"Roger on Excel" wrote:

I use code to hide empty rows on a sheet. This works fine if the cells dont
have formulas in them and are empty.

However, if I use formulas in those rows which return blank cells, the code
doesnt hide the rows.

Even though the formulas in the cells return a zero value based upon
criteria, the rows wont hide.

Here is the code i use:

Dim rng As Range
On Error Resume Next
Range("a28:a54").EntireRow.Hidden = False
Set rng = Range("a28:a54").SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Hidden = True
End If


Can anyone suggest code which will hide the rows if the formulas in cells
a28 to a 54 return zero values?

Thanks,

Roger


JLGWhiz

hiding rows containing formulas which return zero values
 
Had a typo:

Dim c As Range
For Each c In Range("A28:A54")
If c = "" Or c.Value = 0 Then
c.EntireRow.Hidden = True
End If
Next


"Roger on Excel" wrote:

I use code to hide empty rows on a sheet. This works fine if the cells dont
have formulas in them and are empty.

However, if I use formulas in those rows which return blank cells, the code
doesnt hide the rows.

Even though the formulas in the cells return a zero value based upon
criteria, the rows wont hide.

Here is the code i use:

Dim rng As Range
On Error Resume Next
Range("a28:a54").EntireRow.Hidden = False
Set rng = Range("a28:a54").SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng Is Nothing Then
rng.EntireRow.Hidden = True
End If


Can anyone suggest code which will hide the rows if the formulas in cells
a28 to a 54 return zero values?

Thanks,

Roger



All times are GMT +1. The time now is 05:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com