Share via

Macro to copy & paste rectangle shapes

Anonymous
2013-10-30T20:05:50+00:00

My macro (below) copies a named range "EvalCopy3", then paste it on a newly created worksheet.  It works great, but there are some rectangle shapes in the named range (used as macro buttons) - If I set the macro up to do a simple copy and paste the macro buttons are carried over, but the formatting is not - - If I set the macro up to paste the formatting (as is shown below) the page is formatted corretly, but then the macro buttons are not there.

I can't figure out where I'm going wronge here - Thanks.

 Dim wks As Worksheet

    Dim strName As String

    'Copies the evaluation record

    Application.Goto Reference:="EvalCopy3"

    strName = Selection.Range("A1").Value

    On Error Resume Next

    Set wks = Worksheets(strName)

    On Error GoTo 0

    If Not wks Is Nothing Then

        MsgBox "The sheet '" & strName & "' already exists!", vbExclamation

        Exit Sub

    End If

    Selection.Copy

    'inserts a new worksheet, pastes evaluation recor

    Set wks = Sheets.Add(Before:=Sheets("Employee List"))

    With wks.Range("A1")

        .PasteSpecial Paste:=xlPasteValues

        .PasteSpecial Paste:=xlPasteFormats

        .PasteSpecial Paste:=xlPasteColumnWidths

FYI - there is more to this macro - but I didn't want to copy the entire thing, just the area where the copy/paste code is.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2013-10-30T21:40:55+00:00

    Perfection!  Thanks so much.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-10-30T20:22:43+00:00

    Hello,

    you can add a regular paste command after the paste special:

    Sub test()

    Dim wks As Worksheet

    Dim strName As String

    'Copies the evaluation record

    Application.Goto Reference:="EvalCopy3"

    strName = Selection.Range("A1").Value

    On Error Resume Next

    Set wks = Worksheets(strName)

    On Error GoTo 0

    If Not wks Is Nothing Then

    MsgBox "The sheet '" & strName & "' already exists!", vbExclamation

    Exit Sub

    End If

    Selection.Copy

    'inserts a new worksheet, pastes evaluation recor

    Set wks = Sheets.Add(Before:=Sheets("Employee List"))

    With wks.Range("A1")

    .PasteSpecial Paste:=xlPasteValues

    .PasteSpecial Paste:=xlPasteFormats

    .PasteSpecial Paste:=xlPasteColumnWidths

    End With

    ActiveSheet.Paste

    End Sub

    Was this answer helpful?

    0 comments No comments