View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips[_3_] Bob Phillips[_3_] is offline
external usenet poster
 
Posts: 2,420
Default Basic VBA question - hiding rows

Type this in the immediate window in the VBIDE

Application.EnableEvents = True

--
__________________________________
HTH

Bob

"Babymech" wrote in message
...

Hmm... that does help a little, but now I don't know where the error is -
when I had the wrong formatting in there, and I went to the appropriate
sheet
and made selection-change, it showed me the error. When the correct code
is
in place, nothing happens - no error message, but no effect on the rows,
either. Any ideas?

"Pete_UK" wrote:

Note that these lines:

cell.EntireRow.Hidden = Not
cell.EntireRow.Hidden

should be all one line - it has wrapped in the posting, and should be
like this:

cell.EntireRow.Hidden = Not _
cell.EntireRow.Hidden

or like this (without indents):

cell.EntireRow.Hidden = Not cell.EntireRow.Hidden

Hope this helps.

Pete

On Jan 15, 10:21 am, Babymech
wrote:
Thanks for the quick reply - unfortunately I can't get that to work...
When I
insert the code it immediately marks the line cell.entirerow.hidden =
true
as red, and when I try to run it, I get a syntax error. VBA tells med
it
expects an expression there... Any ideas?



"Bob Phillips" wrote:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "A:A" '<== change to suit
Dim cell As Range

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

With Target

If .Row 3 Then

If .Value = Me.Range("A3").Value Then

For Each cell In Me.Range("A4")..Resize(.Row - 3)

If cell.Value < Me.Range("A3").Value Then

cell.EntireRow.Hidden = Not
cell.EntireRow.Hidden
End If
Next cell
End If
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
__________________________________
HTH

Bob- Hide quoted text -

- Show quoted text -