DDDDHHHH
DDDDHHHH

Reputation: 11

VBA : Copy and Paste Range as Picture Works when stepping through but get "run-time Error '1004'" when run

I am having an issue with the code below. I have written a macro to copy and paste pictures of a series of rows, and it works when I step through it. However, when I run the macro, it tends to get stuck on one random paste (usually not a singular one. Please advice how to better write this code to avoid this issue when running the macro

Sub Presentation_Formating()
   Dim wb As Workbook
   Dim pic As Picture
   Dim i As Integer, j As Integer
   Dim content As Worksheet
   Dim presentation As Worksheet

   i = 5
   j = 7

   Set content = Sheets("Recovery Indicator Content")
   Set presentation = Sheets("Recovery Indicator")
   Set wb = ActiveWorkbook

   'Delete all existing pictures besides the photo in the top right
    For Each pic In Sheets("Recovery Indicator").Pictures
        If pic.Name <> "Picture 65" Then
            pic.Delete
        End If
    Next pic
    
    Do Until i > 62
        wb.Sheets("Recovery Indicator Content").Select
        Range(Cells(i, 1), Cells(i + 12, 4)).CopyPicture Appearance:=xlScreen, Format:=xlPicture
        wb.Sheets("Recovery Indicator").Select
        Range(Cells(i + 9, 3), Cells(i + 21, 6)).Select
        ActiveSheet.Paste
        
        i = i + 14
    Loop

    MsgBox ("Done!")
End Sub

Upvotes: 1

Views: 446

Answers (0)

Related Questions