+ Reply to Thread
Results 1 to 16 of 16

Looping through checkboxes in a specified range

  1. #1
    Registered User
    Join Date
    01-18-2024
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    24

    Looping through checkboxes in a specified range

    Hi,

    I have a sheet with checkboxes in columns A e B in many lines and I want to perform some actions based on wheter or not the checkboxes are checked. But I have to do it in each line at a time in a loop. But I am failing in trying to do it, since the OLEobjects apparently are only available to the worksheet object. And also I need help to find the right sintax (the typeof apparently is only valid to useform, not to activex controls.

    Sorry my bad english
    Last edited by MotroJena; 04-06-2024 at 08:10 PM.

  2. #2
    Registered User
    Join Date
    01-18-2024
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    24

    Re: Looping through checkboxes in a specified range

    The relevant sheet is sheet1
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,661

    Re: Looping through checkboxes in a specified range

    I want to perform some actions based on ...the checkboxes...
    You nee to describe the 'actions'. I can't tell from the macro code or the worksheets
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    01-18-2024
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    24

    Re: Looping through checkboxes in a specified range

    Quote Originally Posted by protonLeah View Post
    You nee to describe the 'actions'. I can't tell from the macro code or the worksheets
    Ok, I just need to access those checkboxes, for instance, its names, inside the loop; each line at time, has mentioned

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,646

    Re: Looping through checkboxes in a specified range

    Example
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-18-2024
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    24

    Re: Looping through checkboxes in a specified range

    Quote Originally Posted by jindon View Post
    Example
    Please Login or Register  to view this content.
    Hi thanks for the help

    I debug the code I think this part is giving a problem since the statement fails:
    If TypeName(ob.Object) = "CheckBox" Then

    I replace the checkbox name to the actual checkboxes names ("checkbox1", "checkbox2" ) and still doesn't work.

  7. #7
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,253

    Re: Looping through checkboxes in a specified range

    How about a completely different solution that will allow you to operate on cell values, rather than looking for which checkbox is checked.
    With the following macro, which you run once, you will insert checkboxes in columns E:F. Each checkbox is linked to the cell in which that checkbox is embedded. Selecting a checkbox will insert a TRUE value into the linked cell, unselecting it will insert a FALSE value. In order to make logical values not visible in the cells, a special format (;;;) is used. If the list gets longer in the future, you can run this macro again. Previous selections will be retained.
    Such a solution will allow you to operate on cell values, whether with another macro or with formulas in the worksheet.

    Caution, the macro removes all graphic objects from the sheet. If, in addition to the checkboxes in columns E:F, there will be other objects, these controls should be removed differently.
    Please Login or Register  to view this content.
    Artik

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,646

    Re: Looping through checkboxes in a specified range

    You could check it for yourself.
    Please Login or Register  to view this content.
    Use progID or TypeName whichever useful.

  9. #9
    Registered User
    Join Date
    01-18-2024
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    24

    Re: Looping through checkboxes in a specified range

    Quote Originally Posted by Artik View Post
    How about a completely different solution that will allow you to operate on cell values, rather than looking for which checkbox is checked.
    With the following macro, which you run once, you will insert checkboxes in columns E:F. Each checkbox is linked to the cell in which that checkbox is embedded. Selecting a checkbox will insert a TRUE value into the linked cell, unselecting it will insert a FALSE value. In order to make logical values not visible in the cells, a special format (;;;) is used. If the list gets longer in the future, you can run this macro again. Previous selections will be retained.
    Such a solution will allow you to operate on cell values, whether with another macro or with formulas in the worksheet.

    Caution, the macro removes all graphic objects from the sheet. If, in addition to the checkboxes in columns E:F, there will be other objects, these controls should be removed differently.
    Please Login or Register  to view this content.
    Artik
    Man, It worked beautifully. In fact it is much easier to work with cells values.
    I can't say thank you enough

    Just out of curiousity: what those lines do:

    Application.ScreenUpdating = False

    On Error Resume Next
    ActiveSheet.Shapes.SelectAll
    Selection.Delete
    On Error GoTo 0

    what runtime error it could fire that could be ignored?

  10. #10
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,253

    Re: Looping through checkboxes in a specified range

    Please Login or Register  to view this content.
    Freezes the screen for the duration of the procedure.


    Please Login or Register  to view this content.
    If it were not for error handling this line would report an exception if there were no graphic objects in the sheet.

    Artik

  11. #11
    Registered User
    Join Date
    01-18-2024
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    24

    Re: Looping through checkboxes in a specified range

    Quote Originally Posted by Artik View Post
    How about a completely different solution that will allow you to operate on cell values, rather than looking for which checkbox is checked.
    With the following macro, which you run once, you will insert checkboxes in columns E:F. Each checkbox is linked to the cell in which that checkbox is embedded. Selecting a checkbox will insert a TRUE value into the linked cell, unselecting it will insert a FALSE value. In order to make logical values not visible in the cells, a special format (;;;) is used. If the list gets longer in the future, you can run this macro again. Previous selections will be retained.
    Such a solution will allow you to operate on cell values, whether with another macro or with formulas in the worksheet.

    Caution, the macro removes all graphic objects from the sheet. If, in addition to the checkboxes in columns E:F, there will be other objects, these controls should be removed differently.
    Please Login or Register  to view this content.
    Artik
    Hi Artik,

    In the above worksheet, urged the need to create a command button, which opens an userform, but this code, as you said before, is deleting the button. is there a way to keep the command button?
    Thanks!

  12. #12
    Registered User
    Join Date
    04-17-2024
    Location
    USA
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Re: Looping through checkboxes in a specified range

    Thanks! Artik

  13. #13
    Registered User
    Join Date
    04-17-2024
    Location
    USA
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Re: Looping through checkboxes in a specified range

    I replace the checkbox name to the actual checkboxes names ("checkbox1", "checkbox2" ) and still doesn't work.

  14. #14
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,253

    Re: Looping through checkboxes in a specified range

    Quote Originally Posted by MotroJena View Post
    Hi Artik,

    In the above worksheet, urged the need to create a command button, which opens an userform, but this code, as you said before, is deleting the button. is there a way to keep the command button?
    Instead of lines:
    Please Login or Register  to view this content.
    insert:
    Please Login or Register  to view this content.
    and add procedure in the module:
    Please Login or Register  to view this content.
    Artik

  15. #15
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    260

    Re: Looping through checkboxes in a specified range

    Click on your CheckBox to select it, in the Developer tab (make sure you have that enable), select the "Properties" function. In the box that says "Cell Link", reference the cell the Checkbox is located.

    You can then use that cell as reference to determine if the box is checked, just as you would when looping through cells.

    You can also you my tutorial on how to add Boolean Checkboxes prior to their official implementation later this year: https://www.excelforum.com/tips-and-...tml?highlight=
    Last edited by PrizeGotti; 04-18-2024 at 10:32 AM.

  16. #16
    Registered User
    Join Date
    01-18-2024
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    24

    Re: Looping through checkboxes in a specified range

    Quote Originally Posted by Artik View Post
    Instead of lines:
    Please Login or Register  to view this content.
    insert:
    Please Login or Register  to view this content.
    and add procedure in the module:
    Please Login or Register  to view this content.
    Artik
    Thank you once again!

+ 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. Using forms and checkboxs
    By mdolinger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2021, 04:53 PM
  2. linking filters with checkboxs
    By kez85 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-26-2019, 02:48 AM
  3. [SOLVED] delete all checkboxs in all sheet
    By qzlvyh0524 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-27-2017, 11:13 PM
  4. [SOLVED] Multiple ActiveX Checkboxs
    By aprildu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2017, 04:51 PM
  5. VBA Checkboxs
    By Moepat in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2011, 12:25 PM
  6. Looping Checkboxs
    By jaimie1664 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2010, 11:35 AM
  7. [SOLVED] Checkboxs Move in Document
    By Sherry in forum Excel General
    Replies: 1
    Last Post: 11-22-2005, 04:20 PM

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