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
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
Thanks for the answer, I attach the file
Maybe you can consider using Advanced Filters since you wanted only certain columns in the output.
Refer : https://www.myonlinetraininghub.com/excel-advanced-filters