Reputation: 1
I am having issues formulating a vba code.
My entire goal is the following:
I want to add a Row to a named table (in this case it is named July2020table
).
Paste values into this row from range A20:E20
Delete values from A20:E20
after it has been pasted into newrow
.
This is what I currently have.
Sub AddRowtToBudgetTable()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("July2020Table")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
Range("A20:E20").Copy
This code is currently able to add a row to the table, however I am unable to paste values from A20:E20
into this table.
Upvotes: 0
Views: 40
Reputation: 1139
As proposed by #teylyn ;-)
Option Explicit
Sub AddRowtToBudgetTable()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("July2020Table")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
Range("A20:E20").Copy Destination:=newrow.Range
Range("A20:E20").ClearContents
End Sub
Upvotes: 1
Reputation: 633
Could you try this if it works? Just modify your last row of code
Range("A20:E20").Copy newrow.Range
Range("A20:E20").Delete Shift:=xlToLeft 'or Shift:=xlToUp depending on you
Upvotes: 0