我希望在将值从此工作表映射到另一个工作表之后删除每一行。以下是我目前的代码。行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
答案 0 :(得分:2)
它应该像这样工作:
If Not IsEmpty(Slave.Cells(i, 3)) Then Slave.Cells(i, 3).EntireRow.Delete