Thanks Thanks:  0
Likes Likes:  0
Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: If-Clause in VBA to look at checkbox if its checked or not

  1. #1
    New Member
    Join Date
    Apr 2003
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default If-Clause in VBA to look at checkbox if its checked or not

    Hello!

    let's say i have "check box 20" and i want to make an IF-clause to check, if this same box is checked or unchecked.

    This makes it enabled i have figured out myself yay!

    ActiveSheet.Shapes("Check Box 20").Select
    With Selection
    .Value = xlOn

    So Is it possible to make IF-clause to "sniff" that box if its checked or not?

    Thanks a million!

  2. #2
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    73,092
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You are almost there really:

    Code:
    If ActiveSheet.Shapes("Check Box 20").Value = xlOn Then
      MsgBox "Checked
    Else
      MsgBox "Unchecked
    End If

  3. #3
    New Member
    Join Date
    Apr 2003
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default :(

    Tried that and i get this error message:

    Run-time error '438':

    Object does not support this property or method.

    on debug, following line is highligted:
    If ActiveSheet.Shapes("Check Box 20").Value = xlOn Then

  4. #4
    MrExcel MVP phantom1975's Avatar
    Join Date
    Jun 2002
    Location
    Omaha, Nebraska
    Posts
    3,962
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Are you using the CheckBox found in the FORMS toolbar or the CONTROL TOOLBOX toolbar?
    Silly Billy was here....

    ***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************

  5. #5
    New Member
    Join Date
    Apr 2003
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default toolbar

    Im using FORMS checkbox.

  6. #6
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Good morning...

    MsgBox IIf(CheckBox1.Value, "CHECKED", "UNCHECKED")

    the xlOn constant works, but this is not the correct constant to use. Any non zero value will evaluate to TRUE. xlOn = 1

    Use TRUE or FALSE. If the "TripleState" property is set to true, the above will not do. You would need to test for a third value as well. This being 'Null'.

    Tom

    Yeah. The Control Toolbox. I missed that.

  7. #7
    MrExcel MVP phantom1975's Avatar
    Join Date
    Jun 2002
    Location
    Omaha, Nebraska
    Posts
    3,962
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    DUDE! Your troubles will all melt away if you use the Control Toolbox instead. Give it a whirl and you will see what I mean. The controls there are MUCH more robust.
    Silly Billy was here....

    ***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************

  8. #8
    New Member
    Join Date
    Apr 2003
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default sigh

    none of those are working or im just totally handless :P Changed to the control toolbox checkbox but all i get is errors

    So if anyone will give me tested if-clause that works, ill be happy for rest of this year! thanks

  9. #9
    MrExcel MVP phantom1975's Avatar
    Join Date
    Jun 2002
    Location
    Omaha, Nebraska
    Posts
    3,962
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Put this code on the new CheckBox:

    Code:
    Private Sub CommandButton1_Change()
       If CommandButton1.Value = False Then
          MsgBox "You unchecked the box"
       Else
          MsgBox "You checked the box"
       End If
    End Sub
    Silly Billy was here....

    ***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************

  10. #10
    New Member
    Join Date
    Apr 2003
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default :D

    Thanks a bunch, now im very happy

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com