Select first row in list object

NorthbyNorthwest

Board Regular
Joined
Oct 27, 2013
Messages
154
Office Version
  1. 365
Hi, everyone. I haveExcel template (xltm). I create eachweek a new workbook which contains an Excel table, aka list object, Itransfer/paste data to from another source daily. The new workbook starts with only one list row. I need to copy to first row on Monday, andthen Tuesday thru Friday I need to copy to next row (in other words, append toend/bottom of table. When I use thefollowing line of code on Tuesday thru Friday it works great:

VBA Code:
Dim oNewRow as ListRow
Set oNewRow =Selection.ListObject.ListRows.Add(AlwaysInsert:=True)

But on Monday, it creates a second row and copies toit. I realize my code is asking it toinsert a row. But I don’t know how totest the list object for a first row and select it. I’ve tried to research myself. But nothing I come up with seems towork. Can someone help?
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
By trial and error, I stumbled upon answer.

Code:
If Sheet1.ListObjects("Table1").ListRows.Count = 1 Then
   Set oNewRow = Selection.ListObject.ListRows(1) 
Else 
   Set oNewRow-Selection.ListObject.ListRows.Add(Always Insert:=True) 
End if
 
Upvote 0
Solution

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top