开发者

How to check if a cell is empty?

Looking for coding that checks if cell is empty or not. If it is not empty then move to the next cell group. But I need to check if the next cell group is empty or not. If not, then move to the next and so on.

My Current coding below.

If IsEmpty(ActiveSheet.Range("h3")) Then
    Do
    Checkbox1.Value = True
    Range("H3") = 17002
    Sheets("Sheet1").Ran开发者_高级运维ge("I3") = Printerformat2.Text
Else
    Checkbox1.Value = True
    Range("l3") = 17002
    Sheets("Sheet1").Range("m3") = Printerformat2.Text
End If


You need to use a for loop to iterate through the specified range in "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

Hope that helps?


I think you should have a look at Range("your range").specialcells(xlCellTypeBlanks). This is the fastest way to loop through empty cells.
If you need to loop on non blank cells, you can check if your cell Intersect the empty cells range.


The most optimized way to make sure a cell is not empty is "If Len(cell) <> 0".

You can use .offset to access another cell in relation to it's position from the current cell, or reference it directly, so you can check if it's empty or not.


Use

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

instead of

 IsEmpty(ActiveSheet.Range("h3")) 

Cordially

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜