Paste data in Excel Table

Mo7a86

New Member
Joined
Jun 14, 2022
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hi

I want to copy data (value only) from another sheet to my table with keeping my table format (Using office 2013)

copy the below data

Book1
BCDE
2Column2Column1Column3Column4
31aa11/1/2022
42ba21/2/2022
53ca31/3/2022
64aa41/4/2022
75ba51/5/2022
86ca61/6/2022
97aa71/7/2022
108ba81/8/2022
119ca91/9/2022
1210aa101/10/2022
1311ba111/11/2022
1412ca121/12/2022
1513aa131/13/2022
1614ba141/14/2022
1715ca151/15/2022
1816aa161/16/2022
1917ba171/17/2022
Sheet2



to this below table sheet

Book1
ABCDEFGHIJKL
1table 1
2Column1Column2Column3Column4
3QAR 1.00sa1-Jan-2022
4QAR 2.00gy2-Jan-2022
5QAR 2.00ht3-Jan-2022
6QAR 5.00
7
8
9
10table 2
11Column1Column2Column3Column4Column5Column6Column7Column8Column9Column10Column11
12QAR 1.00adreeddjc5-May-2022
13QAR 1.00befresskr6-May-2022
14QAR 1.00cfgfwwsgt7-May-2022
15QAR 3.00
Sheet1
Cell Formulas
RangeFormula
B6,B15B6=SUBTOTAL(109,[Column1])


i want to paste values only in the first table to match destination formatting
hint: the second sheet has many tables which make it not possible to just copy and paste
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
hint: the second sheet has many tables which make it not possible to just copy and paste
That was a good call out ;)

Give the below a try:
Note: it probably won't work if you have tables "next to" the table you are inserting rows into, since it is inserting entirerows
Also I didn't have your table names so you will need to insert the Copy FROM and Copy TO table names.


VBA Code:
Sub CopyTableData()

    Dim srcTbl As ListObject, destTbl As ListObject
    Dim srcSht As Worksheet, destSht As Worksheet
    Dim srcRowCnt As Long, destRowLast As Long
    
    Set srcTbl = Range("tblSource").ListObject      ' <----- Put in correct table name for Copy FROM Table
    Set destTbl = Range("Table1").ListObject        ' <----- Put in correct table name for Copy TO Table
    Set destSht = destTbl.Parent

    srcRowCnt = srcTbl.DataBodyRange.Rows.Count
    destRowLast = destTbl.DataBodyRange.Rows(destTbl.DataBodyRange.Rows.Count).Row
    
    ' Insert rows below table to make room for table expansion
    destSht.Rows(destRowLast + 2).Resize(srcRowCnt).Insert
    ' Insert rows inside table
    destSht.Rows(destRowLast + 1).Resize(srcRowCnt).Insert
    
    srcTbl.DataBodyRange.Copy
    destSht.Cells(destRowLast + 1, destTbl.Range.Cells(1, 1).Column).PasteSpecial Paste:=xlPasteValues
    
    ' Get new last row
    destRowLast = destTbl.DataBodyRange.Rows(destTbl.DataBodyRange.Rows.Count).Row
    ' Delete rows inserted below table
    destSht.Rows(destRowLast + 2).Resize(srcRowCnt).Delete
    
End Sub
 
Upvote 0
Hi alex thanks for the reply no the tables are above each other but it is like 10 tables i should do this vba and change the names each

So each time i have to write new tables name ?
 
Upvote 0
I am obviously not fully understanding what you are trying to do.
At the moment your source format lines up in format to Table 1 on sheet 2 so I am copying the rows there.
Please give details and examples of what else you want it to do.
 
Upvote 0
Well to be more accurate i am working in a bank so i do some financial analysis the form i have now is word documents so i thought it might be easier if i use excel because the statements i can generate it as excel file too

So the point of my question if i have in the statement like 1000 debit chqs (which means 1000 row)

I want to paste it in my second sheet table 1 with matching the table 1 format not the statement format also shifting the below table which is table 2 down and not writing above it ... what i am doing now is inserting copied cells (i talk the whole row so the below table fully shifted down) between the existing rows so the formulas adjusted automatically and then format painting after that i remvoe the empty cells which i use it in the format painting so i want to know if i can merge all these steps in one formula or vba or any other solution

In my current situation the tables option not working for me so i am working it as normal range but as i said before i have to do three steps each time and in tables i cant insert rows when i have more than one table above each other

So i want a 1 step solution just copy paste and have th shifting down and maych destination formatting and formula adjusted automatically it is sum formula btw

Hope it is more clear now 😁
 
Upvote 0
Did you try the macro ?
If so show me what it did and then what you wanted it to do so I can see the difference.

Is is just that you want column 1 & 2 swapped ?
 
Upvote 0

Forum statistics

Threads
1,216,167
Messages
6,129,262
Members
449,497
Latest member
The Wamp

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