如何检查单元格是否为空?

时间:2011-08-12 15:37:04

标签: excel vba

寻找检查细胞是否为空的编码。如果它不为空,则移至下一个单元组。但我需要检查下一个单元格组是否为空。如果没有,那么转到下一个,依此类推。

我的当前编码如下。

If IsEmpty(ActiveSheet.Range("h3")) Then
    Do
    Checkbox1.Value = True
    Range("H3") = 17002
    Sheets("Sheet1").Range("I3") = Printerformat2.Text
Else
    Checkbox1.Value = True
    Range("l3") = 17002
    Sheets("Sheet1").Range("m3") = Printerformat2.Text
End If

4 个答案:

答案 0 :(得分:1)

您需要使用for循环迭代“H”

中指定的范围
Dim i As Long
With ActiveSheet
  For i = 1 to 500

    If IsEmpty(.Range("h" & CStr(i)).Value) Then
     'Do 'Not sure where you're going with this one? This is not really needed from what I can tell.
     Checkbox1.Value = True
     .Range("H" & CStr(i)).Value = 17002
     Sheets("Sheet1").Range("I" & CStr(i)).Value = Printerformat2.Text
    Else
      Checkbox1.Value = True
      .Range("l" & CStr(i)) = 17002
      Sheets("Sheet1").Range("m" & CStr(i)).value = Printerformat2.Text
    End If

   Next
End With

希望有帮助吗?

答案 1 :(得分:1)

我想你应该看看Range("your range").specialcells(xlCellTypeBlanks)。这是循环空单元格的最快方法 如果您需要循环非空白单元格,则可以检查单元格Intersect是否为空单元格范围。

答案 2 :(得分:0)

确保单元格不为空的最佳方法是“如果L​​en(单元格)<> 0”。

您可以使用.offset从当前单元格访问与其位置相关的另一个单元格,或直接引用它,以便检查它是否为空。

答案 3 :(得分:0)

使用

 Application.WorksheetFunction.isblank(ActiveSheet.range("h3"))

而不是

 IsEmpty(ActiveSheet.Range("h3")) 

亲切

相关问题