IMAGE
希望将此作为for循环,如果它们都包含一个值,则迭代并比较A1与B1,否则跳过并跳转到下一行,将A2与B2比较,将A3与B3比较,依此类推直到大约100。
您可以在我的示例图像中看到,例如A4包含一个值,但B4却不这样,A5和B5相同,但是A6和B6都包含一个值,因此我想删除该行并继续进行:)
Sub Empty_cell()
Dim score1 As Integer, score2 As Integer, result As String, col As Integer, RangeStr1 As String, RangeStr2 As String
col = 4
Let RangeStr1 = "A" & col & ""
Let RangeStr2 = "B" & col & ""
score1 = Range(RangeStr1).Value
score2 = Range(RangeStr2).Value
If score1 >= 0 & score2 >= 0 Then
Range(RangeStr1 & ":" & RangeStr2).Delete
MsgBox "Deleted"
Else
MsgBox "Failed"
col = col + 1 '
MsgBox col
End If
End Sub
最佳答案
您可以使用一个内衬语句来做到这一点:
Range("A4", Cells(Rows.count, "A").End(xlUp)).SpecialCells(xlCellTypeConstants, xlNumbers).Offset(, 1).SpecialCells(xlCellTypeConstants, xlNumbers).EntireRow.Delete
哪里:
Range("A4", Cells(Rows.count, "A").End(xlUp))
引用从第4行到最后一个不为空的所有A列单元格
.SpecialCells(xlCellTypeConstants, xlNumbers)
用数字选择所有引用的范围单元格
.Offset(, 1).
将结果范围向右移一列(即移至B列的相应单元格)
.SpecialCells(xlCellTypeConstants, xlNumbers)
选择后一个带有数字的范围单元格
.EntireRow.Delete
最后删除结果单元格的行