Copy Table row to another Table

Takes2ToTango

Board Regular
Joined
May 23, 2023
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to grab an active cell row and copy that row to another table. However I am only getting errors.

On double click I want to grab the entire line as highlighted in red.
1688540429608.png

This then copies and pastes it into the table below. Once done, any new lines will be added underneath.

1688540506416.png


Many thanks in advance!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Perhaps the below will get you started:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim sTbl As ListObject, dTbl As ListObject
    Dim sRow As ListRow, dRow As ListRow
    
    Set sTbl = Me.ListObjects("Table1") ' change source table name (Me refers to the sheet the code is running in)
    Set dTbl = Me.ListObjects("Table2") ' change destination table name (Me refers to the sheet the code is running in)
    
    If Not Intersect(Target, sTbl.DataBodyRange) Is Nothing Then
        Set sRow = sTbl.ListRows(Target.Row - sTbl.Range.Row) ' set source row
        Set dRow = dTbl.ListRows.Add ' set destination row
        sRow.Range.Copy dRow.Range ' copy the row over
    End If
End Sub
 
Upvote 0
Solution
You are welcome, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,647
Messages
6,126,005
Members
449,279
Latest member
Faraz5023

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