+ Reply to Thread
Results 1 to 14 of 14

For To Loop to Increment ActiveX [EDIT - Now 'Form Control'] CheckBox Numbers

  1. #1
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    For To Loop to Increment ActiveX [EDIT - Now 'Form Control'] CheckBox Numbers

    Hello,

    I've set up 39 Active X checkboxes which, if the same row in B contains data it formats a strikethrough in A2:C39 if checked.

    [EDIT]If it does not contain data then the checkbox hides.

    Here is my code for just the first and last one:

    Please Login or Register  to view this content.
    Is there a way I can use a For To Loop through all the Checkbox numbers 1-39 so I don't have to type the above code out 39 times?

    I searched for an answer and have given this a go myself but nothing I've tried works.
    Last edited by Zedcars; 01-03-2022 at 08:30 AM. Reason: Switched from ActiveX to Form Control so amended the title.

  2. #2
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Sorry, I don't think I was quite clear enough in my initial post. The checkboxes should hide when there is no data in another cell in the same row. And my code above does what I wish, but I would like to streamline the code so I don't have to repeat the code for all the other rows in which I have checkboxes.

    I've tried this code for the last sub, but it isn't hiding the checkbox in D5 say when I delete data from cell B5:

    Please Login or Register  to view this content.
    I have got further along though because it's no longer throwing up an error like my other attempts!
    Last edited by Zedcars; 01-02-2022 at 02:31 PM.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Try
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Quote Originally Posted by Fluff13 View Post
    Try
    Please Login or Register  to view this content.
    Oh wow! That small change and now it works perfectly! Thank you very much.

    I don't suppose there is any way I can do a similar For To Loop for the 39 Private Sub CheckBox1_Click() subs is there?

    I tried:

    Please Login or Register  to view this content.
    but it said expected identifier at the first bracket. Maybe this just isn't possible to do for each object.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    If you used Form Control checkboxes instead, you could assign the same macro to each of them

  6. #6
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Quote Originally Posted by Fluff13 View Post
    If you used Form Control checkboxes instead, you could assign the same macro to each of them
    Ah ok. Would I still be able to hide the checkboxes in the same way I've been doing? I think maybe I have to change the OLEObjects entry to Controls instead or something like that.

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Yes you can do it like
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Quote Originally Posted by Fluff13 View Post
    Yes you can do it like
    Please Login or Register  to view this content.
    Thank you, but that does not work for me. Not sure why. Shouldn't "Check Box" be "CheckBox"? Also, I've seen a similar question answered on Stack Overflow and they use "Me.Controls" instead of "Me.Shapes". Not sure if that makes any difference, but it doesn't work either way.

    I tried this:

    Please Login or Register  to view this content.
    But it's still not working - the checkbox remains visible.

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Shouldn't "Check Box" be "CheckBox"?
    Not unless you have renamed the checkboxes. The default name for a Form Control checkbox is "Check Box"
    Can you supply a workbook?

  10. #10
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    The forum attachment feature doesn't work for me. I will use my Dropbox instead - I hope that is ok:

    https://www.dropbox.com/s/85hg30pxh5...s-06.xlsm?dl=0

    I wasn't able to get the Strikethrough of A:C or the Hide working with the Form Controls.

    I will have to return to ActiveX controls if I'm not able to get this working.

    [Edit: It seems to have attached anyway, without me realising it!!! Haha]
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Re: For To Loop to Increment ActiveX CheckBox Numbers

    Hello,

    I have the ActiveX working just fine, but would rather not use it as I have to have a separate macro for each checkbox. Also, I've read ActiveX can cause many other problems.

    So I've switched to the Form Control checkboxes (which look better anyway!)

    I've got the strikethrough font format working now.

    But hiding the Checkboxes when the adjacent cell in B is empty isn't working.

    I don't know if anyone can help me solve this? It feels like I'm close to an answer, but so far it's stumped me!

    I will attach an updated Excel file with just the barebones.

    Many thanks.
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: For To Loop to Increment ActiveX [EDIT - Now 'Form Control'] CheckBox Numbers

    This code
    Please Login or Register  to view this content.
    needs to go in the sheet module, not a regular module.

  13. #13
    Registered User
    Join Date
    06-23-2021
    Location
    England
    MS-Off Ver
    2010
    Posts
    17

    Re: For To Loop to Increment ActiveX [EDIT - Now 'Form Control'] CheckBox Numbers

    Quote Originally Posted by Fluff13 View Post
    This code
    Please Login or Register  to view this content.
    needs to go in the sheet module, not a regular module.
    Oh you absolute beauty! What you said fleetingly crossed my mind but I thought I had done that. Clearly not. Rookie mistake.

    Wasted 2 hours on this this morning and lots of time yesterday but at least I'm learning!

    Best wishes to you.
    Last edited by Zedcars; 01-03-2022 at 10:07 AM.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: For To Loop to Increment ActiveX [EDIT - Now 'Form Control'] CheckBox Numbers

    Glad to help & thanks for the feedback.

+ 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. [SOLVED] Non UserForm - Checkbox Loop to add numbers and concatenate labels - Part B
    By ecronic in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-12-2020, 09:53 AM
  2. [SOLVED] Non UserForm - Checkbox Loop to add numbers and concatenate labels
    By ecronic in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-01-2020, 10:36 AM
  3. Help needed for ActiveX checkbox VBA
    By thecatlady in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2020, 11:45 AM
  4. Replies: 1
    Last Post: 07-27-2014, 10:57 AM
  5. [SOLVED] How to see the ActiveX Checkbox is checked ?
    By redsab in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-12-2013, 04:37 AM
  6. [SOLVED] Loop through numbered ActiveX CheckBox
    By georgesj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2013, 10:56 AM

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