delete shapes in specific column

  • hello

    i try writing code to remove all of shapes are existed in col a but i failed it gives me error and i search in the internet i have found remove all of shapes in sheet

    this is my trying

    Code
    Sub ClearObjects()
    Dim ws As Range, S As Shape
    For Each ws In Range("a2:a1000")
       For Each S In ws.Shapes
              S.Delete
       Next S
    Next ws
    End Sub
  • Try:


    Code
    For Each S In ws.Shapes
     if not intersect(S.Topleftcell, range("A2:A1000")) Is nothing then S.Delete
     Next S

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Try:


    Code
    For Each S In ws.Shapes
     if not intersect(S.Topleftcell, range("A2:A1000")) Is nothing then S.Delete
     Next S

    I setup my buttons to fit into cells, then tried using intersect method to delete the same shapes, yet some shapes remained. My solution was to name my shapes with the column and row in the shape names, then when I wanted to delete the shapes, loop through all shapes, deleting the shapes per the text in the shape names.


  • hi, jolivanes,RoyUK I would ask if is possible specify the range like a2:c100 instead of col 1 i try adjusting in this line but it gives me error

    If shp.Range("a2:c100") = 1 Then shp.Delete

  • Code
    Sub Maybe()
    Dim ws As Worksheet, shp As Shape
    Set ws = ActiveSheet    '<---- Change to proper sheet name if so desired
    For Each shp In ws.Shapes
    If Not Intersect(shp.TopLeftCell, Range("A2:C100")) Is Nothing Then shp.Delete
    Next shp
    End Sub
  • hi, jolivanes i hope to don't misunderstand me i don't ignore Rory deliberately


    He always solves many problems especially difficulty every time i issue my thread i find him the first person helps , i appreciate him


    thanks all

Participate now!

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