Counting in a userform

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I have 10 combo boxes in a userform frame. I would like
the user to select just ONE combo box. If any more than 2
are select, and before my ActiveCell.Offset updates the
spreadsheet. I would like to catch this multiple input
error and send msgbox then Cancel=true back to the
userform for correction.

My 10 combo's are as follows:
cboA.Value
..
..
cboJ.Value
I thought that I could loop and count, if count great than
1, stop and message, return and correct. My code locked me
up. Thanks.
 
Dan,

Count them and output the msgbox from within the form. If not more than one,
then exit.

This si some code for running from an OK type button.

'-----------------------------------------------------------------
Private Sub Commandbutton1_Click()
'-----------------------------------------------------------------
Dim ctl As msforms.Control
Dim iCbs As Long

For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
If ctl.ListIndex <> -1 Then
i=i+1
If i > 1 Then
MsgBox "Only select one"
Exit Sub
End If
End If
End If
Next ctl

Me.Hide

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Bob, I am a newbie as if you can't tell! Do I have to
replace the Me and the "Combo box"? Because when I run I
get a compile error:wrong # of arguments or invalid
property asignment. Thanks Dan
 
I made an error, go figure. Corrected and works great
Thanks, Dan
-----Original Message-----
Bob, I am a newbie as if you can't tell! Do I have to
replace the Me and the "Combo box"? Because when I run I
get a compile error:wrong # of arguments or invalid
property asignment. Thanks Dan
-----Original Message-----
Dan,

Count them and output the msgbox from within the form.
If
not more than one,
then exit.

This si some code for running from an OK type button.

'--------------------------------------------------------
- -
--------
Dim ctl As msforms.Control
Dim iCbs As Long

For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
If ctl.ListIndex <> -1 Then
i=i+1
If i > 1 Then
MsgBox "Only select one"
Exit Sub
End If
End If
End If
Next ctl

Me.Hide

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
than
locked
.
 
I'm glad about that, as I had no further advice<vbg>

Bob

Dan said:
I made an error, go figure. Corrected and works great
Thanks, Dan
-----Original Message-----
Bob, I am a newbie as if you can't tell! Do I have to
replace the Me and the "Combo box"? Because when I run I
get a compile error:wrong # of arguments or invalid
property asignment. Thanks Dan
-----Original Message-----
Dan,

Count them and output the msgbox from within the form.
If
not more than one,
then exit.

This si some code for running from an OK type button.

'--------------------------------------------------------
- -
--------
Dim ctl As msforms.Control
Dim iCbs As Long

For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
If ctl.ListIndex <> -1 Then
i=i+1
If i > 1 Then
MsgBox "Only select one"
Exit Sub
End If
End If
End If
Next ctl

Me.Hide

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


I have 10 combo boxes in a userform frame. I would like
the user to select just ONE combo box. If any more
than
2
are select, and before my ActiveCell.Offset updates the
spreadsheet. I would like to catch this multiple input
error and send msgbox then Cancel=true back to the
userform for correction.

My 10 combo's are as follows:
cboA.Value
.
.
cboJ.Value
I thought that I could loop and count, if count great than
1, stop and message, return and correct. My code
locked
me
up. Thanks.


.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top