[英]How to check if a cell is empty?
尋找檢查單元格是否為空的編碼。 如果它不為空,則移動到下一個單元組。 但我需要檢查下一個單元組是否為空。 如果沒有,則移至下一個,依此類推。
我的當前編碼如下。
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
您需要使用 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
希望有幫助嗎?
我認為你應該看看Range("your range").specialcells(xlCellTypeBlanks)
。 這是循環空單元格的最快方法。
如果您需要在非空白單元格上循環,您可以檢查您的單元格是否與空白單元格范圍Intersect
。
利用
Application.WorksheetFunction.isblank(ActiveSheet.range("h3"))
代替
IsEmpty(ActiveSheet.Range("h3"))
親切地
確保單元格不為空的最優化方法是“If Len(cell) <> 0”。
您可以使用 .offset 從當前單元格訪問與其 position 相關的另一個單元格,或直接引用它,以便檢查它是否為空。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.