Consulting

Results 1 to 6 of 6

Thread: Excel VBA to Unhide rows with a specific value in a Range

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Excel VBA to Unhide rows with a specific value in a Range

    I have an Excel range that is hidden. I want to unhide only rows in that range C2:F21 that contain a specific value. The value comes from a userform in TextBox3.

    Since find does NOT work on hidden ranges, as far as I can tell, how can I use the Match function to look into the range to do this, OR is there some other useable approach using VBA
    ( Preferred Solution )

    Thanks

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    You want to find the value that's in TextBox three among ALL the cells in C2:F21 (ie. all columns and all rows of that range)?

    ps.
    .Find will search hidden cells if you use LookIn:=xlFormulas, assuming there are no formulas, that is.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Quote Originally Posted by p45cal View Post
    You want to find the value that's in TextBox three among ALL the cells in C2:F21 (ie. all columns and all rows of that range)?

    ps.
    .Find will search hidden cells if you use LookIn:=xlFormulas, assuming there are no formulas, that is.

  4. #4
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    p45cal:

    RE: You want to find the value that's in TextBox three among ALL the cells in C2:F21 (ie. all columns and all rows of that range)?

    To answer your question: Yes!

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Something along these lines
    Private Sub CommandButton1_Click()
    For Each rw In Range("C2:F21").Rows
      For Each cll In rw.Cells
        If cll.Text = TextBox3.Value Then
          cll.EntireRow.Hidden = False
          Exit For
        End If
      Next cll
    Next rw
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    p45cal:

    Thanks.

    The code worked as expected without any errors.

Posting Permissions

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