Consulting

Results 1 to 4 of 4

Thread: Trouble with code to hide rows

  1. #1
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location

    Trouble with code to hide rows

    Hi there

    I am using the code below to hide rows that aren't relevant to a combobox selection.

    Private Sub ComboBox1_Change()
        Dim lr As Long, x As Integer
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        ActiveSheet.Cells.EntireRow.Hidden = False
        If ComboBox1.Value = "Event" Then GoTo Xit
        For x = 5 To lr
           If Cells(x, 5).Value <> ComboBox1.Value Then Rows(x & ":" & x).EntireRow.Hidden = True
        Next
    Xit:
    End Sub
    The code only works correctly every other time, any idea what I'm doing wrong?

    Ticket Bookings.xlsm

    Many thanks
    Semper in excretia sumus; solum profundum variat.

  2. #2
    Hello
    May be you should switch these two lines
        ActiveSheet.Cells.EntireRow.Hidden = False
        lr = Cells(Rows.Count, 1).End(xlUp).Row

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Paul
    ActiveSheet.Cells.EntireRow.Hidden = False
        lr = Cells(Rows.Count, 1).End(xlUp).Row
    Edit: Too late
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Doh!

    Thank you both
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •