+ Reply to Thread
Results 1 to 2 of 2

autofilter to hide rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-16-2009
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2013
    Posts
    114

    autofilter to hide rows

    I wrote this code to hide unused rows on a worksheet but it doesn't seem to do anything.
    I previously had a loop but it was taking too long because the list was too long.

    what did I do wrong?

    any help would be much appreciated.


    Dim ColChk As String
    Dim HideValue As String
    
    ColChk = "I7:I"
    HideValue = ""
    
    Dim Rng As Range
    
    
        With ActiveSheet
            .AutoFilterMode = False
            .Range(ColChk & .Rows.Count).AutoFilter Field:=1, Criteria1:=HideValue
        
                With .AutoFilter.Range
                    On Error Resume Next
                    Set Rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                              .SpecialCells(xlCellTypeVisible)
                    On Error GoTo 0
                    If Not Rng Is Nothing Then Rng.EntireRow.Hidden = True
                End With
        
        End With
    
        If ActiveSheet.AutoFilterMode = True Then
            ActiveSheet.Cells.AutoFilter
            
        End If

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2505
    Posts
    2,790

    Re: autofilter to hide rows

    Not sure what you are trying to do, it would be better to see your sheet and get your desired results to better help you.
    Having said that.
    This code:

    .Range(ColChk & .Rows.Count).AutoFilter Field:=1, Criteria1:=HideValue
    Basically refers to Cell I7 and then all the way to the bottom of the spreadsheet which is a huge number of cells. Rows.count, counts all the rows in the I column and assigns that number. I have Excel 2010 so basically this looks like this on my computer I7:I1048576.

    You then filter by empty cells. Again I'm not sure what you are trying to do, but if what I explained is not what you intended, that's probably part of your problem.

+ 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. Hide rows based on autofilter
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2014, 09:35 AM
  2. [SOLVED] Hide Rows when using autofilter by macro problem
    By Abbadon486 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2014, 11:15 AM
  3. combining hide columns with autofilter rows
    By f1nman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-25-2008, 01:42 PM
  4. [SOLVED] Hide rows that are empty without autofilter between data
    By Tony in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2006, 11:10 PM
  5. faster way to hide rows w/o using autofilter?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2006, 12:45 PM

Tags for this Thread

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