chriscorpion786
Board Regular
- Joined
- Apr 3, 2011
- Messages
- 112
- Office Version
- 365
- Platform
- Windows
Hi All, i have the below code where I am inserting pictures which i have on different sheets in the same workbook. Sometimes, the code works perfectly fine, sometimes it throws up an error at the point of shp.copy.
I cannot debug and try to figure out what is causing the error, everything seems to be fine, should I be using Application.screenupdating = false or is there any bug here.
Kindly advice, my code is as below and I have highlighted in red where the code errors.
I cannot debug and try to figure out what is causing the error, everything seems to be fine, should I be using Application.screenupdating = false or is there any bug here.
Kindly advice, my code is as below and I have highlighted in red where the code errors.
Rich (BB code):
Sub SalesDashboard()
Dim cat As String
Dim tbl As ListObject
Dim row As Long, col As Long
Dim shp As Shape
row = 8
col = 2
cat = Application.Caller
Set tbl = Sheet1.ListObjects("EPOS")
With Sheet2
.Range("AA2").Value = .Shapes(cat).TextFrame2.TextRange.Text
.Range("K35").Value = .Shapes(cat).TextFrame2.TextRange.Text
.Range("AN2").Value = .Shapes(cat).TextFrame2.TextRange.Text
tbl.Range.AdvancedFilter xlFilterCopy, criteriarange:=[Category], copytorange:=.Range("AD2:AJ2"), Unique:=False
For Each shp In .Shapes
If InStr(shp.Name, "SKU") Then shp.Delete
Next shp
'Bring in the category pictures
For Each shp In Sheets(.Range("AA2").Value).Shapes
shp.Copy ' this is where it throws an error sometimes
.Paste .Cells(row, col)
With .Shapes(shp.Name)
.Left = Cells(row, col).Left
.Top = Cells(row, col).Top
.LockAspectRatio = msoFalse
.Width = Cells(row, col).Width
.Height = Cells(row, col).Height * 5
.OnAction = "SKUFilter"
End With
.Shapes("Desc").Duplicate.Name = "Desc" & shp.Name
.Shapes("Desc" & shp.Name).TextFrame2.TextRange.Text = Mid(shp.Name, 4, 10)
With .Shapes("Desc" & shp.Name)
.Left = Cells(row, col).Left
.Top = Cells(row + 6, col).Top
.LockAspectRatio = msoFalse
.Width = Cells(row, col).Width + 10
.Height = 32
.OnAction = "SKUFilter"
End With
.Shapes.Range(Array(shp.Name, "Desc" & shp.Name)).Group.Name = shp.Name
.Shapes(shp.Name).OnAction = "SKUFilter"
If col = 8 Then
col = 2
row = row + 10
Else
col = col + 2
End If
Next shp
.Range("K9").Value = Sheet15.Range("E5").Value
.Range("N9").Value = Sheet15.Range("H5").Value
.Range("K16").Value = Sheet15.Range("E6").Value
.Range("N16").Value = Sheet15.Range("H6").Value
.Range("K23").Value = Sheet15.Range("E7").Value
.Range("N23").Value = Sheet15.Range("H7").Value
End With
End Sub
Last edited by a moderator: