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
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