Hei,
I´ve tweaked a code to copy/paste two different dynamic tables into one dynamic table in another sheet. However, it seems that the latter part of the code (copying the last table) overwrites the first one. I´ve used lastrow to determine the last cell with data, but it failes.
Any suggestions on how to avoid overwriting?
I´ve tweaked a code to copy/paste two different dynamic tables into one dynamic table in another sheet. However, it seems that the latter part of the code (copying the last table) overwrites the first one. I´ve used lastrow to determine the last cell with data, but it failes.
Code:
Sub copyall()
Dim Last_Row1 As Long, Last_Row2 As Long, Last_Row3 As Long
Dim WB1 As Workbook, WB2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim cc As Range
Set WB1 = ThisWorkbook ' Workbook where you want to copy the data
Set ws1 = WB1.Sheets("Sheet1") ' Change the name of your Sheet
Set ws2 = WB1.Sheets("Sheet2") ' Change the name of your Sheet
Set cc = WB1.Sheets("Sheet2").Range("D4:f100")
cc.ClearContents
Last_Row1 = ws1.Range("L" & Rows.Count).End(xlUp).Row ' Determine the lastrow of the data to copy
Last_Row3 = ws1.Range("F" & Rows.Count).End(xlUp).Row ' Determine the lastrow of the data to copy
Last_Row2 = ws2.Range("D" & Rows.Count).End(xlUp).Row + 1 ' Determine the next empty row in order to paste the data
ws1.Range("F5:H" & Last_Row3).Copy ws2.Range("D" & Last_Row2)
ws1.Range("L5:N" & Last_Row1).Copy ws2.Range("D" & Last_Row2)
End Sub
Any suggestions on how to avoid overwriting?