VBA Deleting Source Shape

rwcg2d

New Member
Joined
Jul 11, 2016
Messages
43
Hello, this VBA code will work sometimes, but does not work others. It seems to delete the reference labels & text (Text0 and xLabel0) occasionally when ran (not always). I have confirmed that these values are not found within Worksheets("PoAP (Data)"), so I am unsure why they are disappearing....

The code does the following:
i: Shapes
- Delete all shapes currently with Names (i.e. Shape1, Shape2, Shape3, etc)
- Select, Copy, Paste Shape based on Name of reference shape (i.e. Icon1, Icon2, Icon3, etc)
- Select & Name newly pasted Shape (i.e. Shape1, Shape2, Shape3, etc)
- Resize, Recolor, and Move shape to correct location
- Repeat for i+1

j: Axis Labels
- Delete all labels currently with Names (i.e. xLabel1, xLabel2, xLabel3, etc)
- Select, Copy, Paste Shape based on reference shape (xLabel0)
- Select & Name newly pasted label (i.e. xLabel1, xLabel2, xLabel3, etc)
- Resize, Add Text, and Move label to correct location
- Repeat for j+1

k: Task Text
- Delete all text currently with Names (i.e.Text1, Text2, Text3, etc)
- Select, Copy, Paste Shape based on reference shape (Text0)
- Select & Name newly pasted text (i.e.Text1, Text2, Text3, etc)
- Resize, Add Text, and Move text to correct location
- Repeat for k+1

Code:
Sub PAoP3()Dim i As Integer
i = 3


Do While Worksheets("PoAP (Data)").Cells(i, 5).Value <> ""
Dim R As Integer
Dim G As Integer
Dim B As Integer
R = Worksheets("PoAP (Data)").Cells(i, 6)
G = Worksheets("PoAP (Data)").Cells(i, 7)
B = Worksheets("PoAP (Data)").Cells(i, 8)
    Sheets("Sheet3").Select


On Error Resume Next
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(i, 4).Value).Delete
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(i, 5).Value).Select
    Selection.Copy
    ActiveSheet.Paste
Selection.Name = Worksheets("PoAP (Data)").Cells(i, 4)
With ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(i, 4)).Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(R, G, B)
        .Transparency = 0
        .Solid
End With
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(i, 4)).width = Worksheets("PoAP (Data)").Cells(i, 12).Value
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(i, 4)).height = Worksheets("PoAP (Data)").Cells(i, 11).Value
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(i, 4)).Left = Worksheets("PoAP (Data)").Cells(i, 9)
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(i, 4)).Top = Worksheets("PoAP (Data)").Cells(i, 10)
    i = i + 1
Loop


Dim j As Integer
j = 2


Do While Worksheets("PoAP (Data)").Cells(j, 49).Value <> ""
    Sheets("Sheet3").Select
    
    On Error Resume Next
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(j, 48).Value).Delete
    ActiveSheet.Shapes("xLabel0").Select
    Selection.Copy
    ActiveSheet.Paste
    Selection.Name = Worksheets("PoAP (Data)").Cells(j, 48)
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(j, 48)).DrawingObject.Text = Worksheets("PoAP (Data)").Cells(j, 50)
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(j, 48)).Left = Worksheets("PoAP (Data)").Cells(j, 51) - 25
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(j, 48)).Top = 7
    j = j + 1
Loop




Dim k As Integer
k = 3
Do While Worksheets("PoAP (Data)").Cells(k, 4).Value <> ""
    Sheets("Sheet3").Select
    
    On Error Resume Next
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(k, 16).Value).Delete
    ActiveSheet.Shapes("Text0").Select
    Selection.Copy
    ActiveSheet.Paste
Selection.Name = Worksheets("PoAP (Data)").Cells(k, 16)
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(k, 16)).DrawingObject.Text = Worksheets("PoAP (Data)").Cells(k, 3)
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(k, 16)).width = Worksheets("PoAP (Data)").Cells(k, 18).Value
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(k, 16)).height = Worksheets("PoAP (Data)").Cells(k, 17).Value
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(k, 16)).Left = Worksheets("PoAP (Data)").Cells(k, 13)
    ActiveSheet.Shapes(Worksheets("PoAP (Data)").Cells(k, 16)).Top = Worksheets("PoAP (Data)").Cells(k, 14)
    k = k + 1
Loop


End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Are Text0 and xLabel0 text and label or shapes? You wrote "the reference labels & text (Text0 and xLabel0)". So, they seems to be text and label. Yet, you have "ActiveSheet.Shapes("Text0").Select" and "ActiveSheet.Shapes("xLabel0").Select". Now, they seem to be shapes.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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