值被映射后删除整行

我希望删除每个行后,该值已被映射到另一个表。 以下是我目前的代码。 行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