This is my first post and I'm a beginner VBA programmer so please excuse the rookie question.
I am trying to get paste a value in the last cell of the first column of a table. Up to now, I never used tables and the above was easy as I just used the Rows.Count function. Below is what I have Tried so far:
Sub Add2_TAP_Tracker()
'\\ Add new line
ActiveSheet.ListObjects("Table4").ListRows.Add AlwaysInsert:=True
'\\ Paste Data in New Row
Range("TAP!$C$8").Copy
ActiveSheet.ListObjects("Table4").ListColumns(3).Range
'-->Something to select the last cell and past it...<--
Any help will be appreciated !
Thanks,
Ollie
Sub Range_End_Method()
'Finds the last non-blank cell in a single row or column
Dim lRow As Long
Dim lCol As Long
'Find the last non-blank cell in column A(1)
lRow = Cells(Rows.Count, 1).End(xlUp).Row
'Find the last non-blank cell in row 1
lCol = Cells(1, Columns.Count).End(xlToLeft).Column
MsgBox "Last Row: " & lRow & vbNewLine & _
"Last Column: " & lCol
End Sub
Now adapt the code and add the paste code..
source: http://www.excelcampus.com/vba/find-last-row-column-cell/
The following code creates a new row in a table and then adds data to specific cells in that row. Obviously you alter the amount of columns to match your table.
Dim oNewRow As ListRow
Set oNewRow = Worksheets("YourSheet").Range("TableName").ListObject.ListRows.Add(AlwaysInsert:=True)
oNewRow.Range.Cells(1, 1).Value = 'Some data
oNewRow.Range.Cells(1, 2).Value = 'Some data
oNewRow.Range.Cells(1, 3).Value = 'Some data
oNewRow.Range.Cells(1, 4).Value = 'Some data
oNewRow.Range.Cells(1, 5).Value = 'Some data
oNewRow.Range.Cells(1, 6).Value = 'Some data
oNewRow.Range.Cells(1, 7).Value = 'Some data
oNewRow.Range.Cells(1, 8).Value = 'Some data
Thanks for your replies, I cracked what I was trying to do this morning. Next time I will try with the Rows.Count method as I think my way is a bit long winded:
'\\Add New Line
Range("Table4[[#All],[Received]]").Select
Selection.End(xlDown).Select
Selection.ListObject.ListRows.Add AlwaysInsert:=True
'\\Select+Copy Target Data
Sheets("A Sheet").Select
Range("D8").Copy
'\\Paste Into Tracking Table
Sheets("Tracker").Select
Range("Table4[[#All],[Received]]").Select
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Selection.PasteSpecial xlPasteValues
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.