Consulting

Results 1 to 4 of 4

Thread: Solved: hiding Rows using index number

  1. #1
    VBAX Newbie
    Joined
    Nov 2009
    Posts
    4
    Location

    Smile Solved: hiding Rows using index number

    Using VBA I am trying to reference a cluster of rows to hide in an excel spreadsheet using indexes. Because the rows are variable I can not use a statement such as rows("4:12").hide which only references fixed rows. I can hide each row individually but i find this takes a long time as there are numerous rows to delete (even with screen updating turned off) and the row locations are variable.
    Can anyone suggest a way to achieve my aim.
    Many thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Rows(myVar).Resize(12).Hidden = True
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Turning Bob's code into a routine to which you can easily refer

    [VBA]
    Sub test()
    Call HideRows(4, 12)
    End Sub

    Sub HideRows(Strt As Long, Rws As Long)
    Rows(Strt).Resize(Rws).Hidden = True
    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'

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop
    Turning Bob's code into a routine to which you can easily refer

    [VBA]
    Sub test()
    Call HideRows(4, 12)
    End Sub

    Sub HideRows(Strt As Long, Rws As Long)
    Rows(Strt).Resize(Rws).Hidden = True
    End Sub

    [/VBA]
    Maybe it would be best to make the visibility parameterised as well

    [vba]

    Sub test()
    Call HideRows(4, 12, True)
    End Sub

    Sub HideRows(Strt As Long, Rws As Long, state As Boolean)
    Rows(Strt).Resize(Rws).Hidden = state
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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