View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Macro to hide rows not working

Hi,

Right click your sheet tab, view code and paste this in

Sub sonic()
LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set myrange = Range("B1:B" & LastRow)
For Each c In myrange
If c.Value < "" And c.Value < 1 Then
c.EntireRow.Hidden = True
End If
Next
End Sub

Mike

"Al" wrote:

What I'm trying to achieve is the automatic hiding of entire rows if the
value of a cell, in this case in column B, is < 1. The below example
works...row 6 is hidden.

Sub hide_row()
If Range("B6").Value < 1 Then Range("B6").EntireRow.Hidden = True
End Sub

But when I try to impose this upon a range of column B, then, alas, not the
desired result!

If Range("B6,B9").Value < 1 Then Range("B6,B9").EntireRow.Hidden = True

Can anyone point me in the right direction? Thanks in advance!

Al