Deleting all shapes in all selected cells

Mesh

New Member
Joined
Apr 24, 2024
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi there,
Using the following VBA code (to delete the shapes in the selected cells) doesn't always work. Sometimes it does sometimes it doesn't, crazy right? The same sheet, the same cell layout and no error messages, yet something prevents the deletion. What is it that I'm missing?

Here is the code I'm using to insert the shapes followed by the code that is supposed to delete them based on cell selection:

VBA Code:
Private Sub cmdKantoorwerkHalf_Click()
ActiveSheet.Unprotect
Dim cell As Range
Dim shp As Shape
    
    For Each cell In Selection
        If IsDate(cell.Value) And cell.Interior.Color <> RGB(255, 217, 102) Then
            Set shp = ActiveSheet.Shapes.AddShape(msoShapeRightTriangle, cell.Left, cell.Top, cell.Width, cell.Height)
            shp.Fill.Visible = msoTrue
            shp.Fill.ForeColor.RGB = RGB(0, 255, 0)
            shp.Fill.Transparency = 0.5
            shp.Line.Visible = msoFalse
            cell.Offset(1, 0).Value = "#KH"
        End If
    Next cell


ActiveSheet.Protect
End Sub

The code I'm using to delete the shapes:
VBA Code:
Private Sub cmdWissen_Click()
ActiveSheet.Unprotect
Dim cell As Range
Dim shp As Shape

    For Each shp In ActiveSheet.Shapes
        If Not Intersect(Selection, shp.TopLeftCell) Is Nothing Then
        shp.Delete
        End If
    Next shp

ActiveSheet.Protect
End Sub

Thanks for any help.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Cause of the problem: the shapes were bleeding into other neighboring cells¯\_(ツ)_/¯
Solution: format cell > text control > wrap text.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top