Hello guys,
I'm new to VBA coding, so I used an AI to generate a code for me, but it didn't work as I intended.
I have a workbook with dozens of worksheets, my idea was to put a button with this macro to copy the same cells range of the active worksheet and to paste this values as a new line in another workbook one directory above.
But the code always copy the same values of the first worksheet.
I tried changing the ThisWorkbook.Sheets(1).Range to ActiveSheet.Range, but then the macro copies the registry.xlsx values.
I don't speak English very well, but I hope you understand what I meant.
I'm new to VBA coding, so I used an AI to generate a code for me, but it didn't work as I intended.
I have a workbook with dozens of worksheets, my idea was to put a button with this macro to copy the same cells range of the active worksheet and to paste this values as a new line in another workbook one directory above.
But the code always copy the same values of the first worksheet.
I tried changing the ThisWorkbook.Sheets(1).Range to ActiveSheet.Range, but then the macro copies the registry.xlsx values.
VBA Code:
Sub RegistrarValores()
Dim pastaRegistro As String
pastaRegistro = ThisWorkbook.Path & "\.."
Dim nomePlanilhaRegistro As String
nomePlanilhaRegistro = "registry.xlsx"
Dim celulasParaRegistrar As Variant
celulasParaRegistrar = Array("C2", "C3", "C4", "C5")
Dim wbRegistro As Workbook
Set wbRegistro = Workbooks.Open(pastaRegistro & "\" & nomePlanilhaRegistro)
Dim ultimaLinha As Long
ultimaLinha = wbRegistro.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row + 1
For i = 0 To UBound(celulasParaRegistrar)
wbRegistro.Sheets(1).Cells(ultimaLinha, i + 1).Value = ThisWorkbook.Sheets(1).Range(celulasParaRegistrar(i)).Value
Next i
wbRegistro.Save
wbRegistro.Close
ActiveSheet.PrintOut
End Sub
I don't speak English very well, but I hope you understand what I meant.