+ Reply to Thread
Results 1 to 6 of 6

Hide rows in Excel automatically

  1. #1
    Registered User
    Join Date
    11-18-2015
    Location
    NY, NY
    MS-Off Ver
    10
    Posts
    3

    Hide rows in Excel automatically

    Hi, I figured out how to do this years ago, but I just can't remember now when I need it again. I have a bunch of data in cell range: A7:0444.

    I have a search box where the user can put in any value they want in B2.

    All I want is when a user searches a term in B2, all those rows that don't contain that search value get hidden. When the search box is empty all rows are visible.

    Simple?

  2. #2
    Registered User
    Join Date
    04-28-2013
    Location
    Poznań/Poland
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Hide rows in Excel automatically

    hi,
    Perhaps You should assign that code to event:

    Sub hide_rows()

    Application.Calculation = xlCalculationManual

    for i=444 to 7 step -1
    if workshetfunction.countif(range("a"& i &":o"& i),Range("B2").value)=0 then
    range("a"& i &":o"& i).EntireRow.hidden=true
    end if
    next i

    Application.Calculation =xlCalculationAutomatic
    End Sub

  3. #3
    Registered User
    Join Date
    11-18-2015
    Location
    NY, NY
    MS-Off Ver
    10
    Posts
    3

    Re: Hide rows in Excel automatically

    I got it to work for hiding rows, thank you. I would like when the search box B2 is empty, that when the user hits search on an empty cell, all the rows become visible again. Right now they don't, the user has to go in a un-hide them.

  4. #4
    Registered User
    Join Date
    04-28-2013
    Location
    Poznań/Poland
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Hide rows in Excel automatically

    You are right! I forgot about it

    Sub hide_rows()

    Application.Calculation = xlCalculationManual

    if range("b2").value="" then
    range("A7:0444").EntireRow.hidden=FALSE
    exit sub
    end if

    for i=444 to 7 step -1
    if workshetfunction.countif(range("a"& i &":o"& i),Range("B2").value)=0 then
    range("a"& i &":o"& i).EntireRow.hidden=true
    end if
    next i

    Application.Calculation =xlCalculationAutomatic
    End Sub

  5. #5
    Registered User
    Join Date
    11-18-2015
    Location
    NY, NY
    MS-Off Ver
    10
    Posts
    3

    Re: Hide rows in Excel automatically

    When I cut and paste the code in I get an error message:

    Method Range of Object _Global failed

    The code is then directing me here:

    Sub hide_rows()

    Application.Calculation = xlCalculationManual

    If Range("b2").Value = "" Then
    Range("A7:0444").EntireRow.Hidden = False (THIS LINE IS YELLOW)
    Exit Sub
    End If

    For I = 444 To 7 Step -1
    If workshetfunction.CountIf(Range("a" & I & ":o" & I), Range("B2").Value) = 0 Then
    Range("a" & I & ":o" & I).EntireRow.Hidden = True
    End If
    Next I

    Application.Calculation = xlCalculationAutomatic
    End Sub

    Any Ideas?

  6. #6
    Registered User
    Join Date
    04-28-2013
    Location
    Poznań/Poland
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Hide rows in Excel automatically

    Sub hide_rows()

    Application.Calculation = xlCalculationManual

    If Range("b2").Value = "" Then
    Range("A7:o444").EntireRow.Hidden = False (THIS LINE IS YELLOW) -> It should be 'o' instad of '0' and now it works properly!
    Exit Sub
    End If

    For I = 444 To 7 Step -1
    If workshetfunction.CountIf(Range("a" & I & ":o" & I), Range("B2").Value) = 0 Then
    Range("a" & I & ":o" & I).EntireRow.Hidden = True
    End If
    Next I

    Application.Calculation = xlCalculationAutomatic
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Why do my rows automatically hide in Excel?
    By jessgust in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-15-2017, 04:29 PM
  2. Automatically Hide/Unhide rows in Excel
    By sanjeeva.vakada in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2014, 10:16 PM
  3. How Do I Hide/Unhide Rows in Excel based on a cell Value Automatically?
    By mgarcia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2012, 05:20 AM
  4. Automatically Hide Rows
    By Owlsfan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2008, 10:41 AM
  5. automatically hide rows with zero value
    By hfc21 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-23-2006, 03:40 PM
  6. Hide rows automatically
    By kim in forum Excel General
    Replies: 1
    Last Post: 09-14-2005, 10:05 AM
  7. How do I automatically hide rows
    By RobRoy in forum Excel General
    Replies: 8
    Last Post: 02-02-2005, 10:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1