ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   command button commands to much (https://www.excelbanter.com/excel-discussion-misc-queries/207897-command-button-commands-much.html)

Wanna Learn

command button commands to much
 
Hello I created 15 command buttons below is a sample of the code for
three of them
Private Sub CommandButton1_Click()
Dim myRng As Range

Set myRng = Me.Range("a35:V64")

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

End Sub

Private Sub CommandButton2_Click()
Dim myRng As Range

Set myRng = Me.Range("a65:V96")

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

Private Sub CommandButton3_Click()
Dim myRng As Range

Set myRng = Me.Range("a97:V129")

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

So if a user clicks one of the command buttons it opens the section if they
click the second command button it opens the second section but the first
section remains open - (unless the first command button is clicked)

Only one section should be open at a time .
How can I correct this
thanks in advance
Is there a way that if th


Dave Peterson

command button commands to much
 
I would add a 16th commandbutton that would show all the rows (just in case???).

Then I'd hide all the rows in each procedu

Private Sub CommandButton1_Click()
Dim myRng As Range
Set myRng = Me.Range("a35:V64")

me.rows("35:" & me.rows.count).hidden = true
'or if you want to hide a specific set of rows.
me.rows("35:1234").hidden = true

'and I'd just use the buttons to unhide the row--not as a toggle
myrng.entirerow.hidden = false

'I'd delete this line
'myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)

End Sub

Wanna Learn wrote:

Hello I created 15 command buttons below is a sample of the code for
three of them
Private Sub CommandButton1_Click()
Dim myRng As Range

Set myRng = Me.Range("a35:V64")

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

End Sub

Private Sub CommandButton2_Click()
Dim myRng As Range

Set myRng = Me.Range("a65:V96")

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

Private Sub CommandButton3_Click()
Dim myRng As Range

Set myRng = Me.Range("a97:V129")

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

So if a user clicks one of the command buttons it opens the section if they
click the second command button it opens the second section but the first
section remains open - (unless the first command button is clicked)

Only one section should be open at a time .
How can I correct this
thanks in advance
Is there a way that if th


--

Dave Peterson


All times are GMT +1. The time now is 08:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com