Active Member
March 5, 2018
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
VIP
Trusted Members
June 25, 2016
1 Guest(s)