View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Option Button Macro (Forms Toolbar)

Maybe you could just look at those "other" option buttons:

Option Explicit
Sub testme()

Dim myOB As OptionButton
Dim myGroupName As String
Dim AtLeastOneOtherOBWasUsed As Boolean

With ActiveSheet
Set myOB = .OptionButtons(Application.Caller)

myGroupName = Mid(myOB.GroupBox.Name, 3)

If LCase(myOB.Caption) = "other" Then
.Range("INTL_FX_" & myGroupName).EntireRow.Hidden = False
Else
.Range("INTL_FX_" & myGroupName).EntireRow.Hidden = True
End If

AtLeastOneOtherOBWasUsed = False
For Each myOB In .OptionButtons
If LCase(myOB.Caption) = "other" Then
If myOB.Value = xlOn Then
AtLeastOneOtherOBWasUsed = True
Exit For
End If
End If
Next myOB

.Range("whateveryounamedit").EntireRow.Visible _
= AtLeastOneOtherOBWasUsed

End With

End Sub


AG wrote:

Dave,

Thanks for replying; after re-reading my verbage my explanation was not
as clear as it could have been.

Each group of three option buttons (Canada/US/Other) relates to one
column of possible data (top section of the form has 6 groups of three
and the bottom section has six groups of three as well - a total of 12
possible Other sections to key). The intent is that any one of the Other
buttons from any group of the three will unhide 5 rows of area where the
user keys in data (the top section has its own 5 rows and the bottom
section has its own 5 rows).

The problem I face is figuring out how to ensure that when any 1 of the
6 top section Other buttons is selected the "top" five rows is unhidden
and the same for the bottom section with its unique 5 rows. I thought I
could code each group of 3 option buttons but I ran into problems
because once any second non-Other button was selected, the rows would
hide even though the first Other button was selected and the user keyed
data (particularly bad given that I would like to have the code clear
the 5 cells of data from a column if the user selects Canada/US after
selecting Other and keying data.

Long winded again, but perhaps this captures the issue is greater detail
and clarity.

Thanks in advance,
Dylan

Dave Peterson wrote:

I'm not sure I quite understand, but maybe you can get some ideas out of this:

First, I'd create one group of 3 option buttons with a groupbox around it.

Give each of the optionbuttons a nice caption--make sure one is Other.

Name the groupbox nice: GB1to6 (this will be used later).

Now assign each option button this macro:

Option Explicit
Sub testme()

Dim myOB As OptionButton
Dim myGroupName As String

With ActiveSheet
Set myOB = .OptionButtons(Application.Caller)

myGroupName = Mid(myOB.GroupBox.Name, 3)

If LCase(myOB.Caption) = "other" Then
.Range("INTL_FX_" & myGroupName).EntireRow.Hidden = False
Else
.Range("INTL_FX_" & myGroupName).EntireRow.Hidden = True
End If
End With

End Sub

Show the drawing toolbar and click on the arrow icon. Select the groupbox and
all 3 option buttons.

ctrl-drag them (or copy|paste) to where the second set will be.
rename that groupbox to: GB7to12

and again and again until your done (GB31to36).

By using a nice name, we can strip the leading GB and leave the portion that the
range name is based on.

===
To rename a groupbox. Just rightclick on it (sometimes easier than trying to
select it) and type that name in the namebox (to the left of the formulabar) and
hit enter.

AG wrote:
[original post snipped]


--

Dave Peterson