+ Reply to Thread
Results 1 to 14 of 14

Check list via VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2019
    Location
    India
    MS-Off Ver
    MS 365
    Posts
    68

    Check list via VBA

    Hi,

    I have a check list in excel with more than 100+ rows. I have also added strike through once I click on the checkbox
    my office pc doesn't have the new version of excel with insert-check box feature

    so, I found out below vba code that can help... now the problem is this code works for single rectangle shape. and I have 102 rectangles...

    my rectangles start from Rectangle 11 to 96 and my strikethrough range is from J4 to J89
    and again from rectangle 97 to 102 and strike through range - J95 to J100


    is there a shorter way to tweak this code in such a way that it changes the shape number along with the range of strike through? for each rectangle I have to change the range in 3 different lines as shown below (highlighted in purple). I am attaching sample workbook for easier reference.

    I know that we have ActiveX check box option from developer tab... and I am currently using it... but it does not allow to increase the size of the small square and it won't allow to change background color either.... so I am trying this one out... Please can someone help!


    Sub Rectangle11_Click()
    With ActiveSheet.Shapes("Rectangle 11")
            With .TextFrame2.TextRange.Characters
                .Text = IIf(.Text = "a", "", "a")
                .Font.Name = "Webdings"
                .Font.Size = 12
                 Range("J4").Value = (.Text = "a")
            End With
        End With
    End Sub
    Attached Files Attached Files
    Last edited by Kinjal Doshi; 05-16-2025 at 06:00 AM.

  2. #2
    Forum Contributor
    Join Date
    10-16-2023
    Location
    Poland
    MS-Off Ver
    Excel 2019 32bit WIN10
    Posts
    142

    Re: Check list via VBA

    You can use one procedure.
    Sub Rectangle_Click()
        Dim rc
        Set rc = ActiveSheet.Shapes(Application.Caller)
        With rc.OLEFormat.Object
            .Text = IIf(.Text = "a", "", "a")
            .Font.Name = "Webdings"
            .Font.Size = 12
            .TopLeftCell.Offset(0, -1).Value = (.Text = "a")
        End With
    End Sub
    It should be assigned to each rectangle.

  3. #3
    Registered User
    Join Date
    01-11-2019
    Location
    India
    MS-Off Ver
    MS 365
    Posts
    68

    Re: Check list via VBA

    Hi Tajan,

    Thanks for the tweak... but as I have mentioned... I have 102 rectangles.

    Is there another code that can help assign this to each rectangles?
    my rectangle numbers are from Rectangle 11 to Rectangle 102

  4. #4
    Forum Contributor
    Join Date
    10-16-2023
    Location
    Poland
    MS-Off Ver
    Excel 2019 32bit WIN10
    Posts
    142

    Re: Check list via VBA

    Quote Originally Posted by Kinjal Doshi View Post
    Is there another code that can help assign this to each rectangles?
    my rectangle numbers are from Rectangle 11 to Rectangle 102
    Use code:

    Sub AssignMacro()
        Dim i As Long
        For i = 11 to 102
             ActiveSheet.Shapes("Rectangle " & i).OnAction = "Rectangle_Click"
        Next i
    End Sub
    Edit: The above macro reports an error because there is no "Rectangle 69". There is "Shape 57".
    Last edited by Tajan; 05-16-2025 at 07:25 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    356

    Re: Check list via VBA

    1. Code in Module1

    Option Explicit
    
    Sub check_click()
    Dim shp As Shape
        Set shp = ActiveSheet.Shapes(Application.Caller)
        With shp.TextFrame2.TextRange.Characters
            .Text = IIf(.Text = "a", "", "a")
            .Font.Name = "Webdings"
            .Font.Size = 12
            shp.Parent.Range("J" & shp.TopLeftCell.Row).Value = (.Text = "a")
        End With
    End Sub
    
    Sub AssignMacro()
    Dim i As Long, shp As Shape
        For Each shp In Worksheets("Sheet1").Shapes
            If shp.TopLeftCell.Column = 11 Then shp.OnAction = "check_click"         '    in case there are other shapes on the sheet
        Next shp
    End Sub
    2. Code in ThisWorkbook

    Option Explicit
    
    Private Sub Workbook_Open()
        AssignMacro        '    in case you add new rectangles to column K again
    End Sub
    3. Save file -> Close file -> reopen file
    Last edited by hungt; 05-16-2025 at 06:50 AM.

  6. #6
    Registered User
    Join Date
    01-11-2019
    Location
    India
    MS-Off Ver
    MS 365
    Posts
    68

    Re: Check list via VBA

    Hi Hungt,

    This is awesome! works perfectly
    Thank you so much!

    Regards,
    Kinjal

  7. #7
    Registered User
    Join Date
    01-11-2019
    Location
    India
    MS-Off Ver
    MS 365
    Posts
    68

    Re: Check list via VBA

    Hi Hungt,

    one more help! can you also share a code which can help to de-select all the checkboxes once all my tasks are completed?

  8. #8
    Registered User
    Join Date
    01-11-2019
    Location
    India
    MS-Off Ver
    MS 365
    Posts
    68

    Re: Check list via VBA

    Hi Tajan,

    Thanks!

    Can you or hungt share a code which can help to de-select all the checkboxes once all my tasks are completed?

  9. #9
    Forum Contributor
    Join Date
    10-16-2023
    Location
    Poland
    MS-Off Ver
    Excel 2019 32bit WIN10
    Posts
    142

    Re: Check list via VBA

    Try this:
    Sub DeselectAll()
    Dim i As Long, shp As Shape
        For Each shp In Worksheets("Sheet1").Shapes
            If shp.TopLeftCell.Column = 11 Then shp.OLEFormat.Object.Text = ""      
        Next shp
    End Sub

  10. #10
    Valued Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    356

    Re: Check list via VBA

    Here you go

    Sub uncheck_all()
    Dim shp As Shape
        For Each shp In Worksheets("Sheet1").Shapes
            If shp.TopLeftCell.Column = 11 Then shp.TextFrame2.TextRange.Characters.Text = ""
        Next shp
    End Sub

  11. #11
    Registered User
    Join Date
    01-11-2019
    Location
    India
    MS-Off Ver
    MS 365
    Posts
    68

    Re: Check list via VBA

    Hi Hungt,

    This only unselects the checkbox... but doesn't remove my strikethrough and change back my color to black font
    can you also add a code for this?

  12. #12
    Valued Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    356

    Re: Check list via VBA

    Here you go

    Sub uncheck_all()
    Dim shp As Shape
        For Each shp In Worksheets("Sheet1").Shapes
            If shp.TopLeftCell.Column = 11 Then
                shp.TextFrame2.TextRange.Characters.Text = ""
                shp.Parent.Range("J" & shp.TopLeftCell.Row).Value = False
                With shp.Parent.Range("C" & shp.TopLeftCell.Row)        ' change "C" to the correct one
                    .Font.Color = 0
                    .Font.Strikethrough = False
                End With
            End If
        Next shp
    End Sub

  13. #13
    Forum Contributor
    Join Date
    10-16-2023
    Location
    Poland
    MS-Off Ver
    Excel 2019 32bit WIN10
    Posts
    142

    Re: Check list via VBA

    E.g.
    Sub DeselectAll()
    Dim i As Long, shp As Shape
        For Each shp In Worksheets("Sheet1").Shapes
            If shp.TopLeftCell.Column = 11 Then
                shp.OLEFormat.Object.Text = ""
                shp.TopLeftCell.Offset(0, -1) = False
            End If
        Next shp
    End Sub

  14. #14
    Registered User
    Join Date
    01-11-2019
    Location
    India
    MS-Off Ver
    MS 365
    Posts
    68

    Re: Check list via VBA

    It worked.
    Thank you

    Thanks to both of 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. Replies: 14
    Last Post: 05-02-2024, 03:40 PM
  2. [SOLVED] Search Text from List (multiple columns) and check if List words appears in String
    By dluhut in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-31-2022, 08:25 AM
  3. Check if a list of barcodes would form cluster groups inside of another barcode list
    By hasan mougharbel in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-25-2022, 06:26 AM
  4. [SOLVED] [Google sheet] Check if values in list exists in another list and show them in range
    By jaryszek in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 09-21-2021, 04:50 AM
  5. Replies: 4
    Last Post: 11-05-2014, 09:38 AM
  6. Replies: 0
    Last Post: 06-27-2014, 04:16 PM
  7. Replies: 1
    Last Post: 12-14-2012, 10:11 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