Consulting

Results 1 to 3 of 3

Thread: Setting Value for Checkboxes

  1. #1

    Setting Value for Checkboxes

    I have a worksheet with both checkboxes and textboxes from the Control toolbox.

    I need to cycle through these shapes to clear any text in the textboxes and set the checkboxes to false (no checkmark).

    I have found a way to clear the textboxes, but cannot find a way to identify/reference the checkboxes.

    Sub ClearResponseBox()
     
    Dim responsebox As Shape
    Dim boxname As String
        For Each responsebox In ActiveSheet.Shapes
           boxname = responsebox.Name
     
           If responsebox.Type = 12 And ActiveSheet.OLEObjects(boxname).Object.Text <> "" Then
                ActiveSheet.OLEObjects(boxname).Object.Text = ""
     
           Else
     
            If responsebox.Type = 12 And ActiveSheet.OLEObjects(boxname).Object.Value <> False Then
             ActiveSheet.OLEObjects(boxname).Object.Value = False
     
           End If
       End If
     
       Next responsebox
    End Sub
    I feel lost again

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim obj As OLEObject
    For Each obj In ActiveSheet.OLEObjects

    If TypeName(obj.Object) = "TextBox" Then

    obj.Object.Text = ""
    ElseIf TypeName(obj.Object) = "CheckBox" Then

    obj.Object.Value = False
    End If
    Next obj
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Clearing object on worksheet

    Thanks so much. It works great!

Posting Permissions

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