Copy 4 columns from smart table to other smart table

Adamsxl

New Member
Joined
Apr 18, 2024
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Hello everyone,

I hope you can help me!?
I'm trying to use VBA to copy the first 4 columns from an intelligent/smart table that has 10 or more columns into another intelligent/smart table.
The additional problem is that only the displayed rows from the table should be copied (if filters are set). I have already found out that I have to use “xlCellTypeVisible” for this.

Currently my code looks like this:
VBA Code:
Option Explicit
Sub CopyData()
Worksheets(1).ListObjects("TableCom").ListColumns(2).DataBodyRange.SpecialCells(xlCellTypeVisible).Copy Destination:=Worksheets(2).ListObjects("TableColl").ListColumns(1)
End Sub

I get an Error = runtime error 9

Can you please help me with a working code? I don´t know much about vba.

Thank you and see you soon
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello

Have you try this way? (Change the column number as you like)

VBA Code:
Sub CopyData()
ThisWorkbook.Sheets(1).Range("TableCom").Columns(2).SpecialCells(xlCellTypeVisible).Copy Destination:=ThisWorkbook.Sheets(2).Range("TableColl").Columns(1)
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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