vba - copy paste specific columns from one sheet to another

noidea23

New Member
Joined
Feb 16, 2022
Messages
28
Office Version
  1. 2021
Platform
  1. Windows
Hii im trying to copy and paste columns in sheet 1 to sheet 2 using the codes below:

'''Columns to copy from table1 in sheet1
Ary = Array("Name", "ID", "Language")

'''Define last of of table1 in sheet1
Dim LastRow As Long
Set Table1 = ThisWorkbook.Worksheets("Sheet1").ListObjects("Table1")

'''Copy and paste from sheet 1 to 2
Dim col As Long
col = 1

With Sheet1
For i = LBound(Ary) to UBound(Ary)
Set Fnd = Sheet1.ListObjects("Table1").HeaderRowRange.Find(Ary(i), , , xlWhole, , , False, , False)
If Not Fnd Is Nothing Then
col = col + 1
Table1.Cells(LastRow, Ary(i)).SpecialCells(xlCellTypeVisible).Copy Sheet2.Cells(1, col) ----> i keep getting error in this line
End If
Next i
End With

Any help will be greatly appreciated!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Are you trying to copy the entire column? If so should the header be copied as well?
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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