Error 1004 in a macro

0

I created the following macro:

Sub Extraer1()
'Definir origen y destino que utilizaremos
Dim OrigenHoja As Excel.Worksheet, _
    DestinoHoja As Excel.Worksheet, _
    OrigenCelda As Excel.Range, _
    DestinoCelda As Excel.Range

'Definir las hojas origen y destino
   Set OrigenHoja = Worksheets("Origen")
   Set DestinoHoja = Worksheets("Destino")

'Definir las celdas origen y destino
Const celdaOrg = "A1"
Const celdaDst = "A1"

'Indicar los rangos origen y destino
Set OrigenCelda = OrigenHoja.Range(celdaOrg)
Set DestinoCelda = DestinoHoja.Range(celdaDst)

'Seleccionar los rangos
ActiveSheet.Unprotect
OrigenCelda.Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy

'Pegar en destino
DestinoCelda.PasteSpecial xlPasteValues
Application.CutCopyMode = False

End Sub

When I run it shows me the error '1004' at run time. Error in the Select method of the Range class.

Someone can tell me where the error is.

Thank you.

    
asked by Calej 08.05.2018 в 14:27
source

1 answer

0

You must first activate the sheet on which the rank OrigenCelda is.

Just before ActiveSheet.Unprotect write OrigenHoja.Activate

    
answered by 08.05.2018 / 16:31
source