2

How to delete only 1 checkbox from any particular cell(say in "C38") using Excel VBA?

Community
  • 1
  • 1
  • is it associated with the cell ? do you know the name of that checkbox? [this](http://stackoverflow.com/questions/16818207/excel-vba-uncheck-all-checkboxes-across-entire-workbook-via-commandbutton/16818828#16818828) is a good starting point –  Jul 11 '13 at 13:33
  • Yes it is associated with the same cell (C38) – user2572407 Jul 12 '13 at 02:04
  • Also, please note that the checkbox is unnamed – user2572407 Jul 12 '13 at 02:10
  • I have got the code to delete multiple checkboxes, but just cant seem to delete 1 particular checkbox ‘Code to Delete all checkboxes in a sheet For Each vShape In ActiveSheet.Shapes vShape.Delete Next vShape – user2572407 Jul 12 '13 at 03:17
  • it cannot be unnamed. –  Jul 12 '13 at 07:16

1 Answers1

1

Here is a little guide to how to delete a specific shape

shape name

As you can see, selecting a shape will show you its name in the Name box (placed on the left side of the formula box). In the above example, the name of the selected shape is Rectangle 1
If you want to delete a specific shape you have to know its name (well, if unless it's a specific shape that has its own properties different than any other shape but I will not cover this in here)
The easiest way to get the name of the shape you want to delete it's to click on the shape and look for the name in the Name box.
Once you know the name you can modify your current code and add an if statement to get a match on one item from Shapes collection.

Sub DeleteShape()
    Dim vShape
    For Each vShape In ActiveSheet.Shapes
        If StrComp(CStr(vShape), CStr("Rectangle 1"), 1) = 0 Then
            vShape.Delete
            Exit For
        End If
    Next
End Sub
  • 2
    Thank you so much mehow :) This explanation helped me a great deal!! Its working now :D :D I m so happy!! Thanks!! – user2572407 Jul 15 '13 at 02:06
  • youre welcome. Here on stackoverflow we say thank you by accepting the answer ( green check mark next to the answer ) –  Jul 15 '13 at 07:03