piątek, 10 lipca 2015

Paste to end of table.

Copy... paste, data scraping ...
- pasting add to end of table

- and learn to reuse the same code.

Sub PasteEOTable(NazwaArkusza As String, NazwaTabeli As String)

Dim mojaTabela As ListObject: Set mojaTabela = Worksheets(NazwaArkusza).ListObjects(NazwaTabeli)

With mojaTabela
  If .DataBodyRange.Rows.Count = 1 And .DataBodyRange.Text = "" Then .DataBodyRange.Rows.Delete
   .ListRows.Add AlwaysInsert:=True
  Worksheets(NazwaArkusza).Paste Destination:=.DataBodyRange.Cells(.DataBodyRange.Rows.Count, 1)
End With

End Sub


Sub main()

Call PasteEOTable("Arkusz1", "Tabela2")

End Sub

More to research: It seems that the first (or the 0 row) serves the purpose of saving the formatting and formules for columns. If we delete the first row, it is important to remember how to bring back all the formulas and number or date formatting.

Brak komentarzy:

Prześlij komentarz