+ Reply to Thread
Results 1 to 4 of 4

Same Code Applied to Multiple Checkboxes in Userform

  1. #1
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Same Code Applied to Multiple Checkboxes in Userform

    I thought I'd find this by searching the forum, but no luck. In my userform, I import a bunch of data that may or may not be valid. I use checkboxes so the user can click if the data is valid, all the controls become unlocked and ungreyed, then edit it as necessary. But I really dont want to beleaguer my module with 20 of these checkbox macros. Isnt there a way to apply one macro to all checkboxes in a userform? Thanks. -Luke
    HTML Code: 
    Private Sub check1_Click()
        Dim ctrl As MSForms.Control
        
        'activity is not valid so is greyed out
        If check1 = False Then
            For Each ctrl In data.Frame1.Controls
                If TypeName(ctrl) = "Label" Then
                    ctrl.ForeColor = RGB(150, 150, 150)
                ElseIf TypeName(ctrl) = "CheckBox" Then
                    ctrl.Enabled = False
                Else
                    ctrl.Locked = True
                    ctrl.BackColor = &H80000004
                End If
            Next ctrl
        End If
        
        'activity is valid so can be edited
        If check1 = True Then
            For Each ctrl In data.Frame1.Controls
                If TypeName(ctrl) = "Label" Then
                    ctrl.ForeColor = RGB(0, 0, 0)
                ElseIf TypeName(ctrl) = "CheckBox" Then
                    ctrl.Enabled = True
                Else
                    ctrl.Locked = False
                    ctrl.BackColor = &H80000005
                End If
            Next ctrl
        End If
        
    End Sub

  2. #2
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Same Code Applied to Multiple Checkboxes in Userform

    Never mind. I'm a stoopid fat dummy. I just did a function call for the checkboxes.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,682

    Re: Same Code Applied to Multiple Checkboxes in Userform

    To keep it simple.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Same Code Applied to Multiple Checkboxes in Userform

    Yup. Worked like a charm. Thanks.
    Had to change data.Frame1 to Me("frame" & nmbr) also.
    Looks so much cleaner.
    -Luke

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Userform code to bring up msgbox if two checkboxes are null
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-06-2017, 01:08 PM
  2. [SOLVED] Code for all TextBoxes; Comboboxes and CheckBoxes in an UserForm
    By pipoliveira in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2016, 05:19 AM
  3. Userform with multiple checkboxes with more than 2 criterias
    By Gorbu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-08-2016, 07:54 AM
  4. [SOLVED] Toggle between userform checkboxes for multiple pairs of checkboxes
    By L plates in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-25-2016, 06:31 AM
  5. [SOLVED] Userform with multiple checkboxes used for autofilter
    By JorisDDS in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-21-2014, 10:41 AM
  6. Macro code to check if all checkboxes on userform are false
    By WilliamWu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2013, 03:33 PM
  7. [SOLVED] VBA code - unable to check checkboxes (userform) in Excel 2010
    By mat418pic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2012, 02:59 PM

Tags for this Thread

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