映射值后删除整行

Delete an entire row after the values have been mapped

我希望在将值从这个 sheet 映射到另一个之后删除每一行。以下是我当前的代码。 If Not IsEmpty(Slave.Cells(i, 3)) Then EntireRow.Delete 行(不起作用)是我希望删除行的理想位置,以便在映射后立即删除行并继续执行代码。

但是我似乎无法让它工作。它运行在相当大的数据集上,因此它需要简单但有效。

关于如何执行此操作或使用包含简单代码的模块的任何想法?

Private Sub CommandButton21_Click()

Dim Master As Worksheet 'declare both
Dim Slave As Worksheet

Application.ScreenUpdating = False

Set Master = ThisWorkbook.Worksheets("Unallocated")
Set Slave = ThisWorkbook.Worksheets("Convertor")


For j = 1 To 5000 '(the master sheet)

For i = 1 To 5000 '(the slave sheet) 'for first 1000 cells
    If Trim(Master.Cells(j, 3).Value2) = vbNullString Then Exit For 'if ID cell is blank exit
    If Master.Cells(j, 3).Value = Slave.Cells(i, 1).Value Then
    If IsEmpty(Slave.Cells(i, 3)) Then Exit Sub
        Master.Cells(j, 2).Value = Slave.Cells(i, 3).Value
        Master.Cells(j, 8).Value = Slave.Cells(i, 4).Value
        Master.Cells(j, 9).Value = Slave.Cells(i, 5).Value
        Master.Cells(j, 10).Value = Slave.Cells(i, 6).Value
        Master.Cells(j, 11).Value = Slave.Cells(i, 7).Value
        Master.Cells(j, 12).Value = Slave.Cells(i, 8).Value
        Master.Cells(j, 13).Value = Slave.Cells(i, 9).Value
        Master.Cells(j, 23).Value = Slave.Cells(i, 11).Value
        Master.Cells(j, 24).Value = Slave.Cells(i, 12).Value
        Master.Cells(j, 25).Value = Slave.Cells(i, 13).Value
        Master.Cells(j, 26).Value = Slave.Cells(i, 14).Value
        Master.Cells(j, 27).Value = Slave.Cells(i, 15).Value
        Master.Cells(j, 28).Value = Slave.Cells(i, 16).Value
        If Not IsEmpty(Slave.Cells(i, 3)) Then EntireRow.Delete

    End If
    Next


    Next

Application.ScreenUpdating = True

End Sub

它应该像这样工作:

If Not IsEmpty(Slave.Cells(i, 3)) Then Slave.Cells(i, 3).EntireRow.Delete