A while back I received help from the member simoco on my question Copy Range and Paste Values in another Sheet's specific Range and the copy paste script works wonderful but now I'm in need something a bit different.
I need to copy specific cells from one sheet and paste it on a specific range on another sheet in order to build a "DB".
This means whenever I run the script, it needs to copy the values to the next empty row.
I tried to modify the code mentioned on the other question, by changing the arrays from a Range to a Cell number but it does not work.
I tried this.
Sub Get_Data()
Dim lastrowDB As Long, lastrow As Long
Dim arr1, arr2, i As Integer
With Sheets("DB")
lastrowDB = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
arr1 = Array("A3", "A4", "A6", "B14")
arr2 = Array("A", "B", "D", "E")
For i = LBound(arr1) To UBound(arr1)
With Sheets("Sheet1")
lastrow = Application.Max(3, .Cells(.Rows.Count, arr1(i)).End(xlUp).Row)
.Range(.Cells(3, arr1(i)), .Cells(lastrow, arr1(i))).Copy
Sheets("DB").Range(arr2(i) & lastrowDB).PasteSpecial xlPasteValues
End With
Next
Application.CutCopyMode = False
End Sub
The debug points to
lastrow = Application.Max(3, .Cells(.Rows.Count, arr1(i)).End(xlUp).Row)
I'm not sure how to modify it to make it work as intended.
Thanks in advance for your assistance.