cut table B data and move to table A depending on criteria

mark692

Active Member
Joined
Feb 27, 2015
Messages
321
Office Version
  1. 2016
Platform
  1. Windows
hi guys i have 2 tables A and B, i want to cut and paste the data on table B to A from column Date to Amount, but depending on the table B's column "remarks", i only want to cut and paste the line that has a remark "to copy",,
is it possible on VBA macro?
here is my sample

Book1
ABCDEFGHIJK
1
2Table ATable B
3datenameamountremarksdatenameamountremarks
41-Junjan20004-Augina500to copy
52-Juljoy25005-Mayjason658don’t
61-Markim6001-Junmiguel5963don’t
74-Jungerald5007-Augbimby154don’t
85-Junkris6562to copy
95-Febjoshua100don’t
105-Marcong50to copy
115-Aprcristy9600don’t
12
13
14
15
16
17
18
19
20
Sheet1
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Here's a solution to that:

VBA Code:
Sub CopyTable2ToCopyRowsToTable1()
   
    Dim lobTable1 As ListObject
    Set lobTable1 = Sheet1.ListObjects("Table1")
   
    Dim lobTable2 As ListObject
    Set lobTable2 = Sheet1.ListObjects("Table2")
   
    Dim arr As Variant
    arr = lobTable2.DataBodyRange.Value

    Dim i As Long
   
    Dim LRow As ListRow
   
    For i = LBound(arr) To UBound(arr)
        If arr(i, 4) = "to copy" Then
            Set LRow = lobTable1.ListRows.Add
            With LRow
                .Range(1) = arr(i, 1)
                .Range(2) = arr(i, 2)
                .Range(3) = arr(i, 3)
            End With
        End If
    Next i

End Sub

Source sheet, noting these are Table1 and Table2 respectively:
cut-table-b-data-and-move-to-table-a-depending-on-criteria.1136358.xlsm
ABCDEFGHIJ
1datenameamountremarksdatenameamountremarks
21-Junjan20004-Augina500to copy
32-Juljoy25005-Mayjason658don’t
41-Markim6001-Junmiguel5963don’t
54-Jungerald5007-Augbimby154don’t
65-Junkris6562to copy
75-Febjoshua100don’t
85-Marcong50to copy
95-Aprcristy9600don’t
Sheet1

I have also presumed you mean copy and not cut.

Result:
1594018468888.png
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,603
Members
449,038
Latest member
Arbind kumar

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