Consulting

Results 1 to 7 of 7

Thread: Turn Multiple OptionButtons as False

  1. #1
    VBAX Regular
    Joined
    Apr 2007
    Posts
    41
    Location

    Turn Multiple OptionButtons as False

    Hello,

    Is there a way to turn multiple OptionButtons as False with a command For, instead of using the following procedure?

    Private Sub CommandButton1_Click()OptionButton1.Value = False
    OptionButton2.Value = False
    OptionButton3.Value = False
    OptionButton4.Value = False
    OptionButton5.Value = False
    OptionButton6.Value = False
    OptionButton7.Value = False
    OptionButton9.Value = False
    OptionButton10.Value = False
    OptionButton11.Value = False
    OptionButton12.Value = False
    OptionButton13.Value = False
    OptionButton14.Value = False
    OptionButton15.Value = False
    ...
    End Sub
    Thank you in advance

    Regards
    Microsoft 2010 | VBA 7.1

  2. #2
    Perhaps like so (assuming these are on a userform):
    Private Sub CommandButton1_Click()
        Dim Ct as Long
        For Ct = 1 to 15
            Me.Controls("OptionButton" & Ct).Value = False
        Next
    End Sub
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Regular
    Joined
    Apr 2007
    Posts
    41
    Location
    Quote Originally Posted by Jan Karel Pieterse View Post
    Perhaps like so (assuming these are on a userform):
    Private Sub CommandButton1_Click()
        Dim Ct as Long
        For Ct = 1 to 15
            Me.Controls("OptionButton" & Ct).Value = False
        Next
    End Sub
    Sorry I forgot to mention that the Optionbuttons are in a spreadsheet as an ActiveX control.

    Regards
    Microsoft 2010 | VBA 7.1

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Force the linked cell for each button to FALSE
    Semper in excretia sumus; solum profundum variat.

  5. #5
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Force the linked cell for each button to FALSE
    Semper in excretia sumus; solum profundum variat.

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Private Sub CommandButton1_Click()    
        Dim o As OLEObject
        For Each o In ActiveSheet.OLEObjects
            If TypeName(o.Object) = "OptionButton" Then o.Object = False
        Next o
    End Sub

  7. #7
    VBAX Regular
    Joined
    Apr 2007
    Posts
    41
    Location
    Quote Originally Posted by Kenneth Hobs View Post
    Private Sub CommandButton1_Click()    
        Dim o As OLEObject
        For Each o In ActiveSheet.OLEObjects
            If TypeName(o.Object) = "OptionButton" Then o.Object = False
        Next o
    End Sub
    Thank you Kenneth Hobs! It works like a charm! This is what I was looking for

    Hugs
    Microsoft 2010 | VBA 7.1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •