+ Reply to Thread
Results 1 to 12 of 12

Using Check Box Code for Multiple Check Boxes

  1. #1
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    510

    Using Check Box Code for Multiple Check Boxes

    Greetings,

    I have several check boxes I am using on a User Form; they all will have the same code (with the exception of 2 rows). I know I can rewrite the code for each Check Box, but I would like to have the code run using the check box name.

    The following is what I am using:
    Please Login or Register  to view this content.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Using Check Box Code for Multiple Check Boxes

    Hi,
    Your question, I won't go into it with too many words.
    But What are you really asking?
    The 6 lines of code you posted are all for one checkbox so I honestly cannot make heads or tails out of it.
    I suggest you rephrase and try to explain it in a such a way that somebody that has no idea of what you are trying to achieve can understand it too.
    I'm sure you know what you're asking but it doesn't reflect in the post, and guessing is something I'm not going to do
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    07-07-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    510

    Re: Using Check Box Code for Multiple Check Boxes

    Keebellah,
    What I would like to do is copy and paste the code for each of the Check Boxes. Having the "Check Box Name" automatically inserting into the code.
    Ex:

    Private Sub "Check Box Name"_Click ()

    If "Check Box Name".Value = True Then Sheet1.Range("G818").Value = "True"
    If "Check Box Name".Value = True Then....
    End Sub

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Using Check Box Code for Multiple Check Boxes

    Okay maybe it's me but what code do you want to copy? I honestly have no idea what your are talking about and what you want to achieve.
    Try showing what you have and would you would like to have.
    I think a sample with what you have and what you have in mind that you want to achieve will clear the vision.

    Right now it's like swimming in murky water with my eyes closed.


    And BTW, use code tags to make it readable for the code sections. (like this)


    Please Login or Register  to view this content.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Using Check Box Code for Multiple Check Boxes

    If it's addin checkbox code on-the-fly using vba, then I suggest you take a look at this link
    https://analysistabs.com/vba/add-che...orm-using-vba/
    There are quite a few links with sample code to add checkbox code on-the fly using vba, your BFF Google can be a great help

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: Using Check Box Code for Multiple Check Boxes

    Quote Originally Posted by brentjohn View Post
    ... I would like ... for each of the Check Boxes. Having the "Check Box Name" automatically inserting into the code ...
    ???
    Nothing is ever automatic.
    Someone must always write something to make this "something" work a little ... or not work ... more than a little...
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Using Check Box Code for Multiple Check Boxes

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Using Check Box Code for Multiple Check Boxes

    @ mehmetcik

    Take a look at this.
    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.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Using Check Box Code for Multiple Check Boxes

    Thanks Bakerman.

    Appreciate the lesson.

    I am going to have to modify my sample userforms.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Using Check Box Code for Multiple Check Boxes

    No lesson intended at all (as if you need one) but you assigned the activecontrol name to a variable, which is a good thing, but then you did not apply that variable in the rest of your code.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Using Check Box Code for Multiple Check Boxes

    Hello brentjohn,

    There is another more advanced method known as Sub-Classing. This involves a Class Module which is used to create new objects in VBA or customize existing objects.

    The Sub-Class contains all the features of the base class (The UserForm CheckBox), but has new features added and modifies some existing ones. Thus every instance of this new Sub-Class shares the same code module. A new Sub-Class object is created and linked to each UserForm CheckBox in the UserForm Initialize event. The UserForm code has a Collection of the new Sub-Class objects that keeps them "alive" while the UserForm is open.

    Class Module Code for MyCheckBoxClass
    Please Login or Register  to view this content.
    Code for UserForm
    Please Login or Register  to view this content.
    ThisWorkbook Code to Run the Demo
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  12. #12
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Using Check Box Code for Multiple Check Boxes

    I'd like to point out that the many "=True" in this thread are un-nessesary

    Please Login or Register  to view this content.
    does the same as
    Please Login or Register  to view this content.
    (I know, but its a pet peeve of mine.)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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. Check boxes that delete other check boxes and change the color of another cell.
    By nhamhamilton in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-29-2014, 02:40 PM
  2. [SOLVED] Coding Yes/No option buttons to not allow check boxes or require check boxes
    By HeyInKy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2014, 11:32 PM
  3. Automatically check one or more check boxes when a parent check box is manually checked
    By Steverizer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-28-2013, 01:56 PM
  4. I need a code for presence check to check multiple text boxes and combo boxes
    By Lee_wwfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2013, 01:53 PM
  5. single group of code to reference multiple sequential names of active x check boxes
    By ferrum_equitis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2012, 03:25 AM
  6. Automatic setting of check boxes based on other check boxes?
    By ArchiveMike in forum Excel General
    Replies: 5
    Last Post: 07-31-2012, 09:43 AM
  7. Check Boxes (un-Check multiple Check Boxes)
    By robertguy in forum Excel General
    Replies: 0
    Last Post: 03-23-2005, 08:48 AM

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