Results 1 to 2 of 2
  1. #1
    tarhim47 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    57

    Hide and unhide arrows

    Hi,

    Can someone please help me with the following macro. I am trying to hide all the blank rows. Blanks rows are those rows for which col B is blank.



    Sub hide_rows()
    Dim r As Range
    Dim r1 As Range
    Set r = Range("B1").CurrentRegion
    ActiveSheet.AutoFilterMode = False
    r.AutoFilter Field:=1, Criteria1:="="
    Set r1 = r.Cells.SpecialCells(xlCellTypeVisible)
    Set r1 = r.Offset(1, 0).Resize(Rows.Count - 1, Columns.Count).Cells.SpecialCells(xlCellTypeVisibl e)
    ActiveSheet.AutoFilterMode = False
    r1.Rows.Hidden = True
    End Sub

    I am getting the following error:
    -----------
    Run-time error '1004':

    AutoFilter method of Range class failed
    -----------

    I am a novice VBA user. Do I need to label any columns in order to make this work?

    THANKS for all your help!
    Last edited by tarhim47; 09-20-2011 at 11:03 AM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    This worked:
    Code:
    Sub HideRows()
    Application.ScreenUpdating = False
    Dim i As Integer
    Range(Range("B2"), Sheets("Sheet1").Range("B1048576").End(xlUp).Offset(0, 3)).Select
    On Error Resume Next
    With Selection
        .EntireRow.Hidden = False
        For i = 2 To .Rows.Count
            If IsEmpty(Range("B" & i)) Then
                .Rows(i - 1).EntireRow.Hidden = True
            End If
        Next i
    End With
    Range("A1").Select
    Application.ScreenUpdating = True
    End Sub
    Is there a column that will have a value in every row? If so, use this column in place of B in the line setting Range. If not, will need different criteria to determine bottom of range or else run code through the whole 1048576 rows. How many columns have data?

    I also got filter to work:
    Sub FilterRows()
    Range("B1:B1048576").Select
    Selection.AutoFilter
    ActiveSheet.Range("B1:B1048576").AutoFilter Field:=1, Criteria1:="<>"
    End Sub
    Last edited by June7; 09-21-2011 at 01:01 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-23-2011, 07:11 AM
  2. Replies: 1
    Last Post: 01-10-2011, 12:25 AM
  3. Hide or Unhide Fields in Query using VB
    By SCFM in forum Programming
    Replies: 4
    Last Post: 03-12-2010, 01:24 PM
  4. How can I hide/unhide DB window with a single button?
    By aquaraider in forum Programming
    Replies: 2
    Last Post: 10-09-2009, 07:01 AM
  5. Hide/UnHide forms
    By access in forum Forms
    Replies: 3
    Last Post: 06-03-2009, 07:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums