
03-02-2006, 07:37 PM
|
|
Newcomer
|
|
Join Date: Mar 2004
Posts: 5
|
|
option button change in an array
|
I have a userform with 10 grouped option buttons. I want to be able to click one of them and it deducts a number from a number in a cell (b3:k3) depending on which button A 2 3 4... 10
this part functions correctly
if i click on another button it should add one back onto the deselected button and add one onto the selected button, it runs through the opb1_change sub twice
the first time it detects the deselected buttons caption name but always comes back with the button being enabled.
the second time it works correctly (deducting one from the new button enabled)
Any Ideas
Code:
'this is in class1
Private WithEvents opb1 As MSForms.OptionButton
Dim X As Integer
Dim AddMinus As Integer
Sub SetOptionButton(ByVal opb As MSForms.OptionButton)
Set opb1 = opb
End Sub
Private Sub opb1_change()
If Right(opb1.Caption, 1) <> "A" Then X = opb1.Caption Else: X = 1
If opb1.Enabled = False Then AddMinus = -1 : else AddMinus = 1
End Sub
Sub Main()
Range("a3").Offset(0, X).Value = Range("a3").Offset(0, X).Value - 1*AddMinus
Call AdjustCount
End Sub
Sub AdjustCount()
Select Case X ' red seven
Case "1": Range("l30").Value = Range("l30").Value - 1 * AddMinus
Case "2": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "3": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "4": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "5": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "6": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "7": Range("l30").Value = Range("l30").Value + 1 / 2 * AddMinus
Case "8": Range("l30").Value = Range("l30").Value
Case "9": Range("l30").Value = Range("l30").Value
Case "10": Range("l30").Value = Range("l30").Value - 1 * AddMinus
End Select
End Sub
'this is in userform1
Private Sub UserForm_Initialize()
Dim obj As MSForms.Control, i As Long
For Each obj In Me.Controls
If TypeName(obj) = "OptionButton" Then
i = i + 1
ReDim Preserve c(i)
Set c(i) = New Class1
c(i).SetOptionButton obj
obj.Tag = i
End If
Next
End Sub
|
|