The Range.Copy will be used as it is simple and easy. The Select should be avoided (English) in excel-vba. If you want to use .Select
it is recommended to turn off the screen update before the code start and restart at the end. Application.ScreenUpdating = False
and Application.ScreenUpdating = True
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = ThisWorkbook.Sheets("CONSULTAR")
Set ws2 = ThisWorkbook.Sheets("CIDADES")
'Pode usar .Sheets ou .Worksheets, com o nome entre "" ou com o número de index
'Exemplo de index
'Set ws1 = ThisWorkbook.Sheets(3)
'Set ws2 = ThisWorkbook.Worksheets(4)
rLast = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row + 1
ws1.Range("D6").Copy Destination:=ws2.Cells(rLast, 1)
ws1.Range("E14").Copy Destination:=ws2.Cells(rLast, 2)
Code can be executed by a button or by events, for example: change in worksheet.
1. Worksheet Declaration (Worksheet)
First you declare each worksheet used, to be able to copy from one to another
Dim ws1 As Worksheet :Set ws1 = ThisWorkbook.Sheets("CONSULTAR")
2. Get the last line
The code ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row
gets the last row in column 1, that is "A". And then rLast
sum 1 to write 1 line after last.
rLast = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row + 1
3. Copy and Paste
ws1.Range("D6").Copy
copy cell D6 from Sheet QUERY
Destination:=ws2.Cells(rLast, 1)
glue in column 1 ("A") and row rLast
ws1.Range("D6").Copy Destination:=ws2.Cells(rLast, 1)
Obs.: Next time insert the code in formatting
correct
and not by image.
I believe that can integrate with the post office to make this survey online also.
– Evert