希望将其作为 for 循环,如果 A1 与 B1 都包含值 detele,则迭代并比较它们,否则跳过并跳转到下一行并将 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
地点:
范围("A4", Cells(Rows.count, "A").End(xlUp))
引用从第 4 行到最后一个非空行的所有 A 列单元格
.SpecialCells(xlCellTypeConstants, xlNumbers)
选择所有引用的带有数字的范围单元格
.Offset(, 1).
将结果范围向右移动一列(即 B 列的相应单元格)
.SpecialCells(xlCellTypeConstants, xlNumbers)
选择后面引用的带有数字的范围单元格
.EntireRow.Delete
最后删除结果单元格的行
关于vba - 循环遍历我的行,如果 2 个单元格包含任何值,则删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41440224/