Consulting

Results 1 to 5 of 5

Thread: ActiveSheet.DrawingObjects.delete except...

  1. #1
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location

    ActiveSheet.DrawingObjects.delete except...

    I want to
    ActiveSheet.DrawingObjects.Delete
    Except "Button 219" and "Button 221"
    What would be my VBA approach?

    Michael

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try this Michael:
    [VBA]Sub delSomeshapesFromAllSheets()
    Dim Shp As Shape
    Dim wk As Worksheet
    For Each wk In ActiveWorkbook.Worksheets
    For Each Shp In wk.Shapes
    If Shp.Name <> "Button 219" And Shp.Name <> "Button 221" Then
    Shp.Delete
    End If
    Next
    Next
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Sorry Michael, I misread the question. The previous code was for all worksheets in the workbook. The following is for the active worksheet only...
    [VBA]Option Explicit
    Sub delSomeshapesFromAllSheets()
    Dim Shp As Shape
    For Each Shp In ActiveSheet.Shapes
    If Shp.Name <> "Button 219" And Shp.Name <> "Button 221" Then
    Shp.Delete
    End If
    Next
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    Thank You very much!
    That worked charmingly!
    Michael

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Be sure to mark your thread solved using the thread tools at the top of the page.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •