+ Reply to Thread
Results 1 to 10 of 10

Thread: Hiding rows with comments

  1. #1
    Registered User
    Join Date
    10-31-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    83

    Hiding rows with comments

    I had a macro that I use to automatically hide or expand row that don't have a value or have the word "qnt." in it. It worked great until I started adding comments to certain cells in those rows. Now I get Run-time error '1004': Unable to set the Hidden property of the Range class.

    Can someone edit this macro so that it works with the comments still intact and able to be read after the spreadsheet has been collapsed?

    Private Sub CommandButton1_Click()
    Dim j As Long
    j = Range("A1").End(xlDown).Row
    Rows("2:" & j).Hidden = False
    End Sub
    
    Private Sub CommandButton2_Click()
    Dim r As Range
    Dim r1 As Range
    Set r = Range("A1").CurrentRegion
    r.AutoFilter Field:=1, Criteria1:="=", Operator:=xlOr, Criteria2:="qnt."
    Set r1 = r.Cells.SpecialCells(xlCellTypeVisible)
    Set r1 = r.Offset(1, 0).Resize(Rows.Count - 1, Columns.Count).Cells.SpecialCells(xlCellTypeVisible)
    ActiveSheet.AutoFilterMode = False
    r1.Rows.Hidden = True
    End Sub
    Last edited by cabinetguy; 12-15-2010 at 11:56 AM.

  2. #2
    Registered User
    Join Date
    10-31-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Hiding rows with comments

    Any suggestions?

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Hiding rows with comments

    Hello cabinetguy,

    I am unable to reproduce your problem. Can you post your workbook for review?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    10-31-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Hiding rows with comments

    Ok, attached is the stripped down version, but the collapse function should still be intact, which is what I'm concerned with.
    Attached Files Attached Files

  5. #5
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Hiding rows with comments

    You could reverse the logic:
    Private Sub CommandButton1_Click()
        Me.AutoFilterMode = False
    End Sub
    
    Private Sub CommandButton2_Click()
        Me.UsedRange.Offset(12).AutoFilter _
                Field:=1, _
                Criteria1:="<>", _
                Operator:=xlAnd, _
                Criteria2:="<>qnt.", _
                VisibleDropDown:=False
    End Sub
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    10-31-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Hiding rows with comments

    That works, somewhat. If I only put 1 value in, for example, if I put 1 as the value in A34 and no other values, it only collapses up to row 34. The other rows are still visible. Also, it shows the "sort" drop down for all columns on the entire spreadsheet except for column A, I don't want any drop downs arrows visible
    Last edited by cabinetguy; 12-16-2010 at 02:34 PM.

  7. #7
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Hiding rows with comments

    Do Name Manager > New,

    Name: rgnA

    Scope: Quote

    RefersTo: =INDEX(Quote!$A:$A, ROW(Quote!$A$13)):INDEX(Quote!$A:$A, ROW(Quote!$A$341)-1)

    Then,
    Private Sub CommandButton1_Click()
        Me.AutoFilterMode = False
    End Sub
    
    Private Sub CommandButton2_Click()
        Me.Range("rgnA").AutoFilter _
                Field:=1, _
                Criteria1:="<>", _
                Operator:=xlAnd, _
                Criteria2:="<>qnt.", _
                VisibleDropDown:=False
    End Sub
    BTW, you have a lot of clutter on the sheet, including invisible objects. I suggest you copy the used range to a new workbook and start again.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    10-31-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Hiding rows with comments

    That works as far as not showing the dropdown arrows, but it still stops if only one value is put in to any cell in column A. It works great if 2 or more different parts are selected, but if only one is selected, it stops as soon as it finds that one value.

    I know this sheet is cluttered bad, I am trying to clean it up a bit and get everything working before I make a new clean sheet. There are going to be 53 of these different sheets after everything is said and done.

    I have a few questions on that project as soon as I get this little problem figured out, if you wouldn't mind helping me with that one. I can send a private message to ask some questions that you can answer at your leisure if you want.

  9. #9
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Hiding rows with comments

    See attached.
    Attached Files Attached Files
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    10-31-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Hiding rows with comments

    Attached is the actual sheet that I am working on, with 1 value in A18. When I click "Collapse", row 14-17 collapse, but 19 on down are still visible. If I put another value in any other cells, say A20, then it works properly and all row without a quantity collapse.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0