Forum

excel vba Copying c...
 
Notifications
Clear all

excel vba Copying columns from one table to another

4 Posts
2 Users
0 Reactions
112 Views
(@giannis)
Posts: 4
Active Member
Topic starter
 

I'm a novice to VBA, I found this code with which I transfer data from the table named "GreensTable" with columns to another table. I have raised the columns of the GreensTable table, what should I change in the code so that I can select some of the columns and not move the entire table. How can I choose columns to copy from a table and drag it to the second table Thanks in advance

 

Sub CopyToTable(ByVal SourceList As ListObject, _ ByVal TargetList As ListObject, _ ByVal rng As Range, _ ByVal rng1 As Range)

Dim i As Long, t As Long, s As Long, x As Long, c As Long, lstRow As ListRow

c = SourceList.ListColumns.Count s = WorksheetFunction.Subtotal(3, rng)

With TargetList t = .ListRows.Count + 1 .Resize .Range.Resize(t + s, .ListColumns.Count)

i = t For Each lstRow In SourceList.ListRows If Not lstRow.Range.EntireRow.Hidden

Then TargetList.ListRows(i).Range(1, 9).Value = "p"

TargetList.ListRows(i).Range.Offset(, 1).Resize(1, c).Value = lstRow.Range.Value i = i + 1

End If

Next

End With

 

Sub CopyGreenTable() CopyToTable Range("GreenTable").ListObject, _ Range("SalesTable").ListObject, _ Range("GreenTable").Columns(2), _ Range("SalesTable").Columns(1).EntireColumn end sub

 
Posted : 06/03/2018 2:34 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Giannis

Welcome to the forum.

Please attach a sample file and describe what you want to do.

It will allow us to have a clearer picture.

Sunny

 
Posted : 06/03/2018 7:23 pm
(@giannis)
Posts: 4
Active Member
Topic starter
 

Thanks for the answer, I attach the file

 
Posted : 07/03/2018 4:42 am
(@sunnykow)
Posts: 1417
Noble Member
 

Maybe you can consider using Advanced Filters since you wanted only certain columns in the output.

Refer :  https://www.myonlinetraininghub.com/excel-advanced-filters

 
Posted : 07/03/2018 9:53 pm
Share: