Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Dependent Macro/Toggle Buttons

I have a table with about 20 rows. Rows 1 to 5 are always visible. I have
added 2 toggle buttons, one to expand and collapse rows 6-12 and the second
one to expand rows 13-20. Is there any way I can program toggle button 2 to
become available only after the user has clicked on toggle button 1?

Also, if the user does not enter data in any of rows 6-20, upon closing the
workbook or before printing the worksheet, I want rows 6-20 to be hidden.
(Hope that is not too complex, I barely have programming skills but can
understand if it is explained in simple terms) Much appreciation for any help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dependent Macro/Toggle Buttons

right click on the sheet tab an put in code like this


----- In the sheet module (right click on the sheet tab and select view
code)
Private Sub ToggleButton1_Click()
If Me.ToggleButton1.Value = True Then
Range("6:12").Entirerow.Hidden = True
Me.ToggleButton2.Enabled = True
Else
Range("6:12").EntireRow.Hidden = False
Me.ToggleButton2.Value = False
Me.ToggleButton2.Enabled = False
End If
End Sub

Private Sub ToggleButton2_Click()
if me.ToggleButton2.Value = True
Range("13:20").EntireRow.Hidden = True
else
Range("13:20").EntireRow.Hidden = False
end if
end Sub

Private Sub Worksheet_Activate()
Me.ToggleButton2.Enabled = False
End Sub


---------- In the ThisWorkbook Module

Private Sub Workbook_Open
Worksheets("Sheet2").Activate
Worksheets("Sheet1").Activate
end Sub


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
ProcSheet1
End Sub

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Activesheet.Name = "Sheet1" then
ProcSheet1
End if
End Sub
---------
In a general Module

Sub ProcSheet1()
With Worksheets("Sheet1")
Set rng1 = Range("6:12").EntireRow
Set rng2 = Range("13:20").EntireRow
set sh = Worksheets("Sheet1")
If Application.CountA(rng1) = 0 Then
sh1.ToggleButton1.Value = True
rng1.Hidden = True
Else
sh1.toggleButton1.Value = False
rng1.Hidden = False
End If
If Application.CountA(rng2) = 0 Then
sh1.ToggleButton2.Value = True
rng2.Hidden = True
Else
sh1.ToggleButton2.Value = False
rng2.Hidden = False
End If
End Sub

--
Regards,
Tom Ogilvy


"Chiku" wrote in message
...
I have a table with about 20 rows. Rows 1 to 5 are always visible. I have
added 2 toggle buttons, one to expand and collapse rows 6-12 and the

second
one to expand rows 13-20. Is there any way I can program toggle button 2

to
become available only after the user has clicked on toggle button 1?

Also, if the user does not enter data in any of rows 6-20, upon closing

the
workbook or before printing the worksheet, I want rows 6-20 to be hidden.
(Hope that is not too complex, I barely have programming skills but can
understand if it is explained in simple terms) Much appreciation for any

help


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Dependent Macro/Toggle Buttons

Tom, thank you very much for the code. It worked perfectly!!!!!! I have
very little programming knowledge but it is so awesome when I get answers for
what I need. If I had known I would enjoy playing with programming this much,
I would have done programming in college. Thank you again.

"Tom Ogilvy" wrote:

right click on the sheet tab an put in code like this


----- In the sheet module (right click on the sheet tab and select view
code)
Private Sub ToggleButton1_Click()
If Me.ToggleButton1.Value = True Then
Range("6:12").Entirerow.Hidden = True
Me.ToggleButton2.Enabled = True
Else
Range("6:12").EntireRow.Hidden = False
Me.ToggleButton2.Value = False
Me.ToggleButton2.Enabled = False
End If
End Sub

Private Sub ToggleButton2_Click()
if me.ToggleButton2.Value = True
Range("13:20").EntireRow.Hidden = True
else
Range("13:20").EntireRow.Hidden = False
end if
end Sub

Private Sub Worksheet_Activate()
Me.ToggleButton2.Enabled = False
End Sub


---------- In the ThisWorkbook Module

Private Sub Workbook_Open
Worksheets("Sheet2").Activate
Worksheets("Sheet1").Activate
end Sub


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
ProcSheet1
End Sub

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Activesheet.Name = "Sheet1" then
ProcSheet1
End if
End Sub
---------
In a general Module

Sub ProcSheet1()
With Worksheets("Sheet1")
Set rng1 = Range("6:12").EntireRow
Set rng2 = Range("13:20").EntireRow
set sh = Worksheets("Sheet1")
If Application.CountA(rng1) = 0 Then
sh1.ToggleButton1.Value = True
rng1.Hidden = True
Else
sh1.toggleButton1.Value = False
rng1.Hidden = False
End If
If Application.CountA(rng2) = 0 Then
sh1.ToggleButton2.Value = True
rng2.Hidden = True
Else
sh1.ToggleButton2.Value = False
rng2.Hidden = False
End If
End Sub

--
Regards,
Tom Ogilvy


"Chiku" wrote in message
...
I have a table with about 20 rows. Rows 1 to 5 are always visible. I have
added 2 toggle buttons, one to expand and collapse rows 6-12 and the

second
one to expand rows 13-20. Is there any way I can program toggle button 2

to
become available only after the user has clicked on toggle button 1?

Also, if the user does not enter data in any of rows 6-20, upon closing

the
workbook or before printing the worksheet, I want rows 6-20 to be hidden.
(Hope that is not too complex, I barely have programming skills but can
understand if it is explained in simple terms) Much appreciation for any

help



Reply
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
have toggle buttons but everytime print preview buttons move TinSandhu Excel Discussion (Misc queries) 1 October 11th 06 02:57 PM
Toggle command buttons GEB Excel Programming 4 June 23rd 05 08:33 PM
Colouring Stuff, Toggle Buttons Momo Excel Programming 2 February 9th 05 03:19 PM
Toggle Buttons Momo Excel Programming 2 February 9th 05 01:35 PM
multiple toggle buttons Nelson Excel Programming 3 November 2nd 04 08:27 AM


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

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"