Macro Copy selection from one Worksheet to another

Asked

Viewed 22 times

-1

Hello! I have a macro of a "Control of Forms" button that copies the data of a selection of a Spreadsheet and pastes (Values and Original Formatting) in a selection of another Worksheet, however, if I try to pass this macro to put in an Activex button the error occurs "Runtime error '1004': Application definition or object definition error"

The macro is as follows:

Private Sub Fechar_Click()
'
' Fecha Macro
' Fechar Mês
'
' Atalho do teclado: Ctrl+Shift+L
'
    Range("A1:AF6").Select
    Selection.Copy
    Sheets("Planilha2").Select
    Range("A2:AF7").Select
    Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Rows("1:7").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1:AF1").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
End Sub

How to adjust the error?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.