How to delete checkboxes in a specific cell range

  • Hi all,


    I currently have a piece of code that deletes all checkboxes on a worksheet:


    Code
    For Each c In Sheets("Sheet1").CheckBoxes
    c.Delete
    Next


    I'm trying to get it to delete checkboxes only in 2 specific cell ranges (C21:C600) and (I21:I600), but I can't figure out how to do this.


    I've tried adding ".Range..." after the sheet name in the statement but it's not being recognised...


    Is there a way to delete checkboxes in these specific ranges and leave all others on that sheet in place?


    Any help would be greatly appreciated!!


    Thanks,

  • Re: How to delete checkboxes in a specific cell range


    Try this

    Code
    For Each c In Sheets("Sheet1").CheckBoxes
        If not Intersect(c.TopLeftCell, Range("C21:C600,I21:I600")) Is Nothing Then
            c.Delete
        End If
    Next

    There is also a BottomRightCell property.

  • Re: How to delete checkboxes in a specific cell range


    Hi Stephen,


    Thanks very much for the response! I've just tried that and it's coming up with an error:


    Run-time error '1004':
    Method 'Intersect' of object '_Global' failed


    When I click Debug it highlights the following line in yellow:


    If Not Intersect(c.TopLeftCell, Range("C21:C600,I21:I600")) Is Nothing Then

  • Re: How to delete checkboxes in a specific cell range


    Oops

    Code
    For Each c In Sheets("Sheet1").CheckBoxes 
        If Not Intersect(c.TopLeftCell, Sheets("Sheet1").range("C21:C600,I21:I600")) Is Nothing Then 
            c.Delete 
        End If 
    Next

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!