Consulting

Results 1 to 14 of 14

Thread: Solved: Hide rows

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location

    Question Solved: Hide rows

    I would like to run a Macro that will search rows 12 to 111 and 112 to 212 and when cell "A" is empty, hide the row.

    How can that be done???

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I don't understand the two ranges. Give this a try. The first lines are to increase the UsedRange size, as SpecialCells appears not to work outwith it.
    [VBA]Sub HideRows()
    Cells(Rows.Count, 1) = "x"
    Cells(Rows.Count, 1).ClearContents
    Range(Cells(12, 1), Cells(111, 1)).SpecialCells(xlCellTypeBlanks).RowHeight = 0
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Sorry about the 2 ranges...

    Let's say I want to hide rows in which cell "A" is empty (between row 12 to 212), what would the macro be like???

    Thanks!!!

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Change 111 to 212 in my previous code. If you have data after row 212, you can delete the first 2 lines of the routine.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    So basically, all I need to add is the following in my Macro???

    Range(Cells(12:212)).SpecialCells(xlCellTypeBlanks).RowHeight = 0

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Range("A12:A212").SpecialCells(xlCellTypeBlanks).RowHeight = 0[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Doesn't work...

    Gives me an error message when I launch the macro and reach the line mentionned above!!!

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post your workbook?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Here is what I have in my macro:

    [VBA]Windows("Fall - 2009 (30’s).xls").Activate
    Sheets("OTT-OCT").Select
    Range(“A12:A212”).RowHeight = 12,75
    Windows("recap - Fall - 2009 (30's).xls").Activate
    Sheets("OTT-OCT").Select
    Range("A12:I212").Select
    Selection.Copy
    Windows("Fall - 2009 (30’s).xls").Activate
    Sheets("OTT-OCT").Select
    Range("A12").Select
    ActiveSheet.Paste
    Windows("recap - Fall - 2009 (30's).xls").Activate
    Sheets("OTT-OCT").Select
    Range("P12:T212").Select
    Selection.Copy
    Windows("Fall - 2009 (30’s).xls").Activate
    Sheets("OTT-OCT").Select
    Range("P12").Select
    Sheets("OTT-OCT").Select
    ActiveSheet.Paste
    Range(“A12:A212”).SpecialCells(x1CellTypeBlanks).RowHeight = 0
    Range("A1").Select
    Windows("recap - Fall - 2009 (30's).xls").Activate
    Windows("Fall - 2009 (30’s).xls").Activate
    Sheets("Tally FALL 2009").Select[/VBA]

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Add some error handling in case there are no blanks

    [vba]
    On Error Resume Next
    Range("A12:A212").SpecialCells(xlCellTypeBlanks).RowHeight = 0
    On Error GoTo 0

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Nope!!! Nothing... But why can't I just add something in my macro that will hide any rows between rows 12 and 212 where cell "A" is blank??? Like for example (I know it's not like that but anyways):

    Range(A12:A212).select
    If a = empty
    then hide.row

    You see what I mean???

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Refer to post #8
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Can't post my document... Too big and it also include many confidential company informations!!! Sorry!!!

  14. #14
    VBAX Regular
    Joined
    Aug 2009
    Posts
    21
    Location
    Did a bit of digging on the net and found this:

    Range(“A12:A212”).Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.Hidden = True


    This works great...

Posting Permissions

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