+ Reply to Thread
Results 1 to 3 of 3

VB code for showing/hiding the following 20 rows?

Hybrid View

mxoxossg VB code for showing/hiding... 03-30-2012, 09:46 AM
mccrimmon Re: VB code for... 03-30-2012, 10:00 AM
mxoxossg Re: VB code for... 03-30-2012, 10:13 AM
  1. #1
    Registered User
    Join Date
    03-30-2012
    Location
    Tamworth, EN
    MS-Off Ver
    Excel 2007?
    Posts
    14

    VB code for showing/hiding the following 20 rows?

    I have buttons that show and hide specific sets of rows:

    Sub COLCHESTER_HIDE()
    '
    ' COLCHESTER_HIDE Macro
    '
    
    '
        Rows("255:274").Select
        Selection.EntireRow.Hidden = True
    End Sub
    Sub COLCHESTER_SHOW()
    '
    ' COLCHESTER_SHOW Macro
    '
    
    '
        Rows("254:275").Select
        Selection.EntireRow.Hidden = False
        Range("A255:B255").Select
    End Sub
    I have 60 locations to do this for!

    Is there any way I can just tell excel to hide/show the next 20 rows rather than having to record each macro individually?
    Last edited by arlu1201; 03-30-2012 at 10:04 AM. Reason: Code tags not quote tags

  2. #2
    Forum Contributor mccrimmon's Avatar
    Join Date
    02-19-2004
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    249

    Re: VB code for showing/hiding the following 20 rows?

    You do not need to select the rows.

    This code will do the exact same thing and run quicker.

    Rows("254:275").Hidden = False
    Rows("276:296").Hidden = True
    Rows("297:317").Hidden = False
    The above example is if you need to hardcode the row numbers.

    If you want it to do the first 20 hidden then the next 20 shown followed by the next 20 hidden then you would need to put these in a loop
    McCrimmon

  3. #3
    Registered User
    Join Date
    03-30-2012
    Location
    Tamworth, EN
    MS-Off Ver
    Excel 2007?
    Posts
    14

    Re: VB code for showing/hiding the following 20 rows?

    I have little no code experience so I am literally recording these macros individually.

    Is it going to be possible for me to have one macro (one piece of code) that I can use on every button.

    For reference, rows 1, 2, 23, 44, 65, 86, 107 etc etc are the rows that I want shown. I want a button next to each of these rows that shows (and similarly hides, can be in a separate button) the next 20 rows.

    edit: p.s. thank you!!!

+ 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.6.0 RC 1