Consulting

Results 1 to 3 of 3

Thread: Copy Paste Shapes to Different Worksheets Loop

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Copy Paste Shapes to Different Worksheets Loop

    Hi folks,

    I have a list of shapes i need to copy and paste to different worksheets,
    I just cant seem to get it right.

    In Column A I have put the worksheet name
    Column B Shape Name

    Example

    Worksheet ---- Shape Name
    Jan ------- ShapeX
    Feb--------- ShapeY


    I would like to copy the shapes to the correct worksheet. these are basic shapes like rectangles

    Sub CopyPasteShape()
    
       Dim wsh        As Worksheet
        Dim oDest     As Worksheet
        
        Dim i      As Integer
        Dim oShape As Shape
        
        oDest = wsh.Cells(i, "A").Value2
        
        Set wsh = Worksheets("Shapes")
        For i = 3 To wsh.Cells(wsh.Rows.Count, "A").End(xlUp).Row
        
        
        Set oShape = wsh.Shapes(wsh.Cells(i, "B").Value2).Copy
        
        oShape = wsh.Shapes(wsh.Cells(i, "B").Value2).Copy
        wsh.Cells(i, "A").Value2.Paste
        
       
        Next i
       
    End Sub
    I dont know how to make the syntax correct,

    thanks for helping

    dj
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Sub CopyPasteShapes()    
      Dim wsh As Worksheet, oDest As Worksheet
        Dim i As Long, oShape As Shape, oShape2 As Shape
         
        'On Error Resume Next
        Set wsh = Worksheets("Shapes")
        
        For i = 3 To wsh.Cells(wsh.Rows.Count, "A").End(xlUp).Row
          Set oDest = Worksheets(wsh.Cells(i, "A").Value2)
          Set oShape = wsh.Shapes(wsh.Cells(i, "B").Value2)
          oShape.Copy
          oDest.Paste
          Application.CutCopyMode = False
          Set oShape2 = oDest.Shapes(oDest.Shapes.Count)
          With oDest.Range("A" & i)
            oShape2.Top = .Top
            oShape2.Left = .Left
            oDest.Activate
            .Select
            wsh.Select
          End With
        Next i
    End Sub

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Thank you very much Kenneth,

    this worked a treat!

    Really appreciate the help

    dj
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •