rockatheman1
rockatheman1

Reputation: 107

Copy Dynamic Range Into the Bottom of a Table

I have the following code:

Sub From_Output_To_Database()

Dim wsImport As Worksheet, wsDB As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Dim Database As ListObject
Dim Data As Range


Set wsOutput = Worksheets("Output")
Set wsDB = Worksheets("DATABASE")

Set StartCell = wsOutput.Range("A2")

Set Database = wsDB.ListObjects("DATABASE")

  LastRow = wsOutput.Cells(wsOutput.Rows.Count, StartCell.Column).End(xlUp).Row
  LastColumn = wsOutput.Cells(StartCell.Row, wsOutput.Columns.Count).End(xlToLeft).Column

  Set Output = wsOutput.Range(StartCell, wsOutput.Cells(LastRow, LastColumn))

Output.Copy

'Here should be the code to paste it into the bottom of the table on a new row.


End Sub

I tried to google for a few hours but all the code that I write either pastes it on top of the existing table or doesn't work at all.

I hope someone here could help me out.

Upvotes: 1

Views: 235

Answers (1)

BigBen
BigBen

Reputation: 50162

  • Add a new row to the table using ListRows.Add.
  • Paste into the first cell of that row.
Dim newRow As ListRow
Set newRow = Database.ListRows.Add()

Output.Copy
newRow.Range.Cells(1).PasteSpecial xlPasteValues

Upvotes: 1

Related Questions