Formula or VBA? Copy and paste Table rows.

somfin4u2c

New Member
Joined
Mar 17, 2015
Messages
11
I have a sheet that has 4 tables.
Let's say tables are A, B, C, and D.
Table B has columns A-O, if column O has the value of W then copy that row (Column's A-N) and paste to the next available row of table D.

Any help would be greatly appreciated.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
what are the names of the 2 tables?
what should trigger the code to run?
 
Upvote 0
Those are not the names of your tables
 
Upvote 0
Thanks - will update thread when back at PC later this morning (UK)
 
Upvote 0
Tests on a COPY of your data first

Place code below goes in SHEET code window (not in a Module like Module1)

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim tapS As ListObject, tapG As ListObject
    Dim Rng As Range, pasteHere As Range
    
    If Target.CountLarge > 1 Then Exit Sub
    Set tapS = Me.ListObjects("TAPS")
    Set tapG = Me.ListObjects("TAPG")
    Set Rng = Intersect(Target, tapS.ListColumns(15).DataBodyRange)

    If Not Rng Is Nothing Then
        If Target = "W" Then
            tapG.ListRows.Add AlwaysInsert:=True
            Set pasteHere = tapG.Range(tapG.ListColumns(1).Range.Rows.Count, 1).Resize(, 14)
            Application.EnableEvents = False
            pasteHere.Value = Me.Cells(Target.Row, "A").Resize(, 14).Value
            Application.EnableEvents = True
        End If
    End If
End Sub
 
Upvote 0
Tests on a COPY of your data first

Place code below goes in SHEET code window (not in a Module like Module1)

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim tapS As ListObject, tapG As ListObject
    Dim Rng As Range, pasteHere As Range
   
    If Target.CountLarge > 1 Then Exit Sub
    Set tapS = Me.ListObjects("TAPS")
    Set tapG = Me.ListObjects("TAPG")
    Set Rng = Intersect(Target, tapS.ListColumns(15).DataBodyRange)

    If Not Rng Is Nothing Then
        If Target = "W" Then
            tapG.ListRows.Add AlwaysInsert:=True
            Set pasteHere = tapG.Range(tapG.ListColumns(1).Range.Rows.Count, 1).Resize(, 14)
            Application.EnableEvents = False
            pasteHere.Value = Me.Cells(Target.Row, "A").Resize(, 14).Value
            Application.EnableEvents = True
        End If
    End If
End Sub
Thank you it works, one little problem though. I have a total row in table TAPG. Your VBA does paste the data into the total row then a blank row is inserted above the total row. If I turn the total row off, then it works perfectly. Is there a fix for this, if not I am sure I can muddle by without a total row?
 
Upvote 0
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim tapS As ListObject, tapG As ListObject
    Dim Rng As Range, pasteHere As Range
    
    If Target.CountLarge > 1 Then Exit Sub
    Set tapS = Me.ListObjects("TAPS")
    Set tapG = Me.ListObjects("TAPG")
    Set Rng = Intersect(Target, tapS.ListColumns(15).DataBodyRange)

    If Not Rng Is Nothing Then
        If Target = "W" Then
            tapG.ShowTotals = False
            tapG.ListRows.Add AlwaysInsert:=True
            Set pasteHere = tapG.Range(tapG.ListColumns(1).Range.Rows.Count, 1).Resize(, 14)
            Application.EnableEvents = False
            pasteHere.Value = Me.Cells(Target.Row, "A").Resize(, 14).Value
            Application.EnableEvents = True
            tapG.ShowTotals = True
        End If
    End If
End Sub
 
Upvote 0
Solution
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim tapS As ListObject, tapG As ListObject
    Dim Rng As Range, pasteHere As Range
   
    If Target.CountLarge > 1 Then Exit Sub
    Set tapS = Me.ListObjects("TAPS")
    Set tapG = Me.ListObjects("TAPG")
    Set Rng = Intersect(Target, tapS.ListColumns(15).DataBodyRange)

    If Not Rng Is Nothing Then
        If Target = "W" Then
            tapG.ShowTotals = False
            tapG.ListRows.Add AlwaysInsert:=True
            Set pasteHere = tapG.Range(tapG.ListColumns(1).Range.Rows.Count, 1).Resize(, 14)
            Application.EnableEvents = False
            pasteHere.Value = Me.Cells(Target.Row, "A").Resize(, 14).Value
            Application.EnableEvents = True
            tapG.ShowTotals = True
        End If
    End If
End Sub
Worked perfectly, Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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