Trouble pasting row to table

后端 未结 1 1623
不知归路
不知归路 2021-01-27 11:20

For every cell that is not blank in column \"Transition\" of table \"TableQueue\", I want to:
1)Copy from table \"TableQueue\" the entire table row that contains that cell,

相关标签:
1条回答
  • 2021-01-27 11:49

    Trans_new_NPD_row.Range is the range for the new row you just added, so you should be able to use something like

    Set Trans_new_NPD_row = ThisWorkbook.Sheets("NPD").ListObjects("TableNPD").ListRows.Add 
    
    Trans_new_NPD_row.Range.Value = _
             Application.Intersect(TransCell.EntireRow, QueueTable.DataBodyRange).Value
    

    EDIT: here's a working example of moving rows from one table to another, using the listobject/table methods

    Sub tester()
    
        Dim tblQueue As ListObject, tblNPD As ListObject, c As Range, rwNew As ListRow
        Dim rngCol As Range, n As Long
    
        Set tblQueue = Sheet1.ListObjects("Queue")  '<< source table
        Set tblNPD = Sheet2.ListObjects("TableNPD") '<< destination table
    
        Set rngCol = tblQueue.ListColumns("Col3").DataBodyRange
    
        'loop from the bottom to the top of the source table
        For n = tblQueue.ListRows.Count To 1 Step -1
            'move this row?
            If rngCol.Cells(n) = "OK" Then
                Set rwNew = tblNPD.ListRows.Add
                rwNew.Range.Value = tblQueue.ListRows(n).Range.Value
                tblQueue.ListRows(n).Delete
            End If
        Next n
    
    End Sub
    

    Source table (destination has the same format):

    0 讨论(0)
提交回复
热议问题