manuvizcarra
New Member
- Joined
- Jun 14, 2021
- Messages
- 3
- Office Version
- 2016
- Platform
- Windows
Hello MrExcel community, I´m new to VBA and I´d like to know if someone knows what´s wrong with my code.
The code should copy a range from workbook "ReporteCNG.xlsx" and paste it in workbook "Consumos CNG1.xlsx".
However, when I run into an error in the line where I try to copy the range from Workbook "ReporteCNG.xlsx") Worksheet("Sheet1")
Sub Copy_Paste_CNG()
Workbooks.Open "C:\Users\manuv\Documents\PELSA\Consumos CNG1.xlsx"
Dim fila As Long
Dim cng As Worksheet
Dim desc As Worksheet
Dim prueba As Range
fila = Cells(Rows.Count, 1).End(xlUp).Row
Set cng = Workbooks("Consumos CNG1.xlsx").Worksheets("General")
Set desc = Workbooks("ReporteCNG.xlsx").Worksheets("Sheet1")
Set prueba = Workbooks("Consumos CNG1.xlsx").Worksheets("Hoja1").Range("A1")
desc.Range(Cells(2, 1), Cells(fila, 18)).Copy prueba
Workbooks("Consumos CNG1.xlsx").Close SaveChanges:=True
End Sub[/CODE]
Thank you for your help!
The code should copy a range from workbook "ReporteCNG.xlsx" and paste it in workbook "Consumos CNG1.xlsx".
However, when I run into an error in the line where I try to copy the range from Workbook "ReporteCNG.xlsx") Worksheet("Sheet1")
Sub Copy_Paste_CNG()
Workbooks.Open "C:\Users\manuv\Documents\PELSA\Consumos CNG1.xlsx"
Dim fila As Long
Dim cng As Worksheet
Dim desc As Worksheet
Dim prueba As Range
fila = Cells(Rows.Count, 1).End(xlUp).Row
Set cng = Workbooks("Consumos CNG1.xlsx").Worksheets("General")
Set desc = Workbooks("ReporteCNG.xlsx").Worksheets("Sheet1")
Set prueba = Workbooks("Consumos CNG1.xlsx").Worksheets("Hoja1").Range("A1")
desc.Range(Cells(2, 1), Cells(fila, 18)).Copy prueba
Workbooks("Consumos CNG1.xlsx").Close SaveChanges:=True
End Sub[/CODE]
Thank you for your help!