+ Reply to Thread
Results 1 to 3 of 3

Clear fields & Checkboxes in a worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-14-2009
    Location
    Planet Earth
    MS-Off Ver
    Excel 2007
    Posts
    5

    Clear fields & Checkboxes in a worksheet

    I have a form that I've created, and I want to add a button that clears the user inputted fields, as well as any one of the four check boxes that may (or may not have) been checked.

    The checkboxes that I want cleared are contained within a group called "Group 1", and my code to clear the cells is below:

    Sub clearfields_insolworksheet()
    '
    ' clearfields_insolworksheet Macro
    '
    
    '
        Range( _
            "C3:E3,H3:L3,C5:E5,H5:L5,G10:I10,G12:I12,G14:I14,C20:D20,G20:H20,K20:L20,C24:D24,G24:H24,K24:L24" _
            ).Select
        Range("K24").Activate
        Range( _
            "C3:E3,H3:L3,C5:E5,H5:L5,G10:I10,G12:I12,G14:I14,C20:D20,G20:H20,K20:L20,C24:D24,G24:H24,K24:L24,G33,I33,L33,I35:L35,I37:L37,C37:E37" _
            ).Select
        Range("C37").Activate
        Selection.ClearContents
        Range("A1").Select
    End Sub
    I'm quite unfamiliar with VBA, so I'm not sure how to add the functionality of clearing the check boxes. What do I do?

  2. #2
    Registered User
    Join Date
    05-14-2009
    Location
    Planet Earth
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Clear fields & Checkboxes in a worksheet

    Bump.. Anyone?

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Clear fields & Checkboxes in a worksheet

    Are the checkboxes ActiveX controls or form controls?

    For form controls:
    Dim chk As CheckBox
    
    For Each chk In ActiveSheet.CheckBoxes
        chk.Value = False
    Next chk

    for ActiveX controls:
    Dim oleChk As OLEObject
    
    For Each oleChk In ActiveSheet.OLEObjects
        If LCase(oleChk.progID) = "forms.checkbox.1" Then oleChk.Object.Value = False
    Next oleChk
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

+ 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