+ Reply to Thread
Results 1 to 5 of 5

checkboxes and code

  1. #1
    Soniya
    Guest

    checkboxes and code

    Hi All,

    I have several checkboxes in a userform

    I want to run the same code if any one or several of them is selected
    or run another code if anyone of them or several of them deselected.

    How can i do this..

    Thanks for all the help


  2. #2
    Ron de Bruin
    Guest

    Re: checkboxes and code

    Do you mean this ?

    Private Sub CheckBox1_Click()
    If Me.CheckBox1.Value = True Then
    'macro 1
    Else
    macro2
    End If
    End Sub


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl



    "Soniya" <[email protected]> wrote in message news:[email protected]...
    > Hi All,
    >
    > I have several checkboxes in a userform
    >
    > I want to run the same code if any one or several of them is selected
    > or run another code if anyone of them or several of them deselected.
    >
    > How can i do this..
    >
    > Thanks for all the help
    >




  3. #3
    Soniya
    Guest

    Re: checkboxes and code

    in that case i have to write code for each checkbox click or change
    event. in my case any check box in the form i have to call the same
    macro


  4. #4
    Ron de Bruin
    Guest

    Re: checkboxes and code

    If you have many then see
    http://www.j-walk.com/ss/excel/tips/tip44.htm

    --
    Regards Ron de Bruin
    http://www.rondebruin.nl



    "Soniya" <[email protected]> wrote in message news:[email protected]...
    > in that case i have to write code for each checkbox click or change
    > event. in my case any check box in the form i have to call the same
    > macro
    >




  5. #5
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Soniya,

    To cover more than one checkbox, do the following:

    (a) In your Userform module:
    Option Explicit
    Dim Buttons() As New ChkClass

    Private Sub UserForm_Initialize()
    Dim n As Integer
    Dim ctl As Control
    n = 1
    For Each ctl In Me.Controls
    If ctl.Name = "CheckBox" & n Then
    ReDim Preserve Buttons(1 To n)
    Set Buttons(n).ButtonGroup = ctl
    n = n + 1
    End If
    Next

    End Sub

    (b) Create a Class module and name it "Chkclass"; then put :
    Public WithEvents ButtonGroup As MsForms.CheckBox
    Sub ButtonGroup_Click()
    MsgBox ButtonGroup.Name
    Call TriggerCode
    End Sub

    (c) finally, put in a general module the code you want to run:
    Sub TriggerCode()
    <Code ... >
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1