vba - How to copy table rows without knowing it's containing sheet -
i want copy data 1 table another, 1 workbook another. know table names, identical. source table has unknown number of data rows plus unknown number of empty rows. destination table (same name, same sheet) has empty rows, not same overall number of rows origin.
i know can
sourcebook.activate activesheet.listobjects(knowntablename).databodyrange.select selection.copy destinationbook.activate activesheet.listobjects(knowntablename).databodyrange.select activesheet.paste
however there number of problems:
- the table not on activesheet. how find sheet table on? or there better way reference (ideally without having find sheet first)?
- i know
.activate
,selection.copy
slow , bad. how can better? - how find "used" data range of both tables without looping through table rows?
- is possible copy data row row (so non empty rows copied)? ideally, insert non-empty source rows destination table , subsequently delete empty rows in destination table
to answer question 2:
dim losource listobject dim lodestination listobject set losource = ... 'to set lodestination = ... 'to lodestination.range(2,1).resize(losource.listrows.count, losource.listcolumns.count).value = losource.databodyrange.value
Comments
Post a Comment