excelraider
excelraider

Reputation: 1

How to copy/paste values in a to a set dimensional array and delete after done

I am having issues formulating a vba code.

My entire goal is the following:

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

Answers (2)

simple-solution
simple-solution

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

Wils Mils
Wils Mils

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

Related Questions