LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default code to hide/unhide rows

i'm looking for a way to create a button in excell that can be placed within
a spreadsheet to control the visiblity of a fixed number of rows. i
currently have the following code in place:

Private Sub CommandButton1_Click()
Dim myRng As Range

Set myRng = Me.Range("a2:a10")

myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)

End Sub

Private Sub CommandButton2_Click()
Dim myRng As Range

Set myRng = Me.Range("a12:a20")

myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)

End Sub

I am not VB savvy in the slightest sense and thankfully found this code
online, but I ran into a problem once a row is inserted between rows
containing the command button. Example:

Row 1 has Command Button 1 that controls the hiding/unhiding of rows 2-10
Row 11 has a Command Button 2 that controls the hiding/unhiding of rows 12-20

I insert a row above Row 11 (Command Button 2 shifts along with the row,
which is ideal), but by doing so the range in the VB code does not adjust to
the downward shift, causing Command Button 2's code to pertain to the wrong
range now that the button is in Row 12.

Is there a way to create a hide/unhide button with coding that adjusts it's
range after it's commanding button is shifted into a different row?

- cheetah

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling option „Format rows“ to hide/unhide rows using VBA-code? ran58 Excel Discussion (Misc queries) 0 July 28th 09 03:46 PM
VB Code to hide and unhide rows Raj Excel Discussion (Misc queries) 2 February 27th 08 05:58 AM
VB Code to hide and unhide rows Raj Excel Programming 0 February 26th 08 05:34 AM
Hide Rows (Current Date) / Unhide Rows Joe K. Excel Programming 1 October 10th 07 05:37 PM
Code for button to hide/unhide rows Chris Excel Worksheet Functions 5 March 5th 07 06:15 AM


All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"