Delete diagram from sheet

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,364
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Two questions.

1) I have some code that will create a Vertical Org Chart, but when I'm ready to run the code again for a new Org Chart, how do I delete the Diagram.

I recorded the action to delete the diagram, but the number may not be the same every time.

VBA Code:
Sub Macro1()
    ActiveSheet.Shapes.Range(Array("Diagram 1")).Delete
End Sub

2) How can I align the diagram starting in D11 and resized to a bigger size?
 
How about this for deleting the diagrams.

VBA Code:
Sub del()
For Each dObj In ActiveSheet.DrawingObjects
    If InStr(dObj.Name, "Diagram") > 0 Then dObj.Delete
Next dObj
End Sub

And passing a variable.

VBA Code:
Sub test(dName As String)
    Set oSALayout = Application.SmartArtLayouts(104)
    Set oShp = ActiveWorkbook.ActiveSheet.DrawingObjects(dName)
    With oShp
        .Width = 600
        .Height = 600
        .Left = Range("D1").Left
        .Top = Range("D1").Top
    End With
End Sub
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,214,657
Messages
6,120,764
Members
448,991
Latest member
Hanakoro

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