Hi. I am trying to write the VBA to paste some selected data into a table that may have no data (so top row is blank) or may have several rows of data.
In my code I select the table head and do end down, but in a blank table this finds row 1 which is empty so data needs to be pasted here. If there is already data it needs to offset down one row before pasting. I can't work out what is wrong with the If clause as for blank table rows will be 1 I assume so does nothing and pastes, where as with data it would drop down one row then paste?
Thanks for any advice as sure simple to people clever than me
mike
In my code I select the table head and do end down, but in a blank table this finds row 1 which is empty so data needs to be pasted here. If there is already data it needs to offset down one row before pasting. I can't work out what is wrong with the If clause as for blank table rows will be 1 I assume so does nothing and pastes, where as with data it would drop down one row then paste?
VBA Code:
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("CombinedData")
Sheets("Associate Detail").Select
Range("C5:V5").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Combined").Select
Range("CombinedData[[#Headers],[Associate Name]]").Select
Selection.End(xlDown).Select
With tbl.DataBodyRange
If .Rows.Count > 1 Then
ActiveCell.Offset(1, 0).Select
End If
ActiveSheet.Paste
Range("CombinedData[[#Headers],[Associate Name]]").Select
End With
Thanks for any advice as sure simple to people clever than me
mike