我想刪除行只有當日期是過去的今天,但不是如果它是未來或空白。現在,如果沒有空白,我很難讓代碼不刪除行,因爲我想保留沒有日期的行。刪除行如果日期已經過去了,但不是如果單元格是空白VBA
Sub deleteSpudedWells()
Dim lastRow As Integer
Dim firstRow As Integer
Dim ctr As Integer
Dim currentCell As Range
Dim valueOfDColumn
Dim NoNSpudedWells As Boolean
lastRow = 300
firstRow = 10
Application.ScreenUpdating = False
With Sheets("NDIC Renewals")
For ctr = lastRow To firstRow Step -1
Set currentCell = .Cells(ctr, 4)
valueOfDColumn = currentCell.Value
NoNSpudedWells = valueOfDColumn >= Date
If Not NoNSpudedWells Then
Debug.Print "deleting row of cell " + currentCell.Address
currentCell.EntireRow.Delete
End If
Next
End With
Application.ScreenUpdating = True
End Sub
如果單元格爲空,豈不是空「」? – bonCodigo
@bonCodigo不,從技術上講它是空的。當作爲數字使用時,它的計算結果爲0.所以,在這方面,它將= 0.它也會=「」。在這方面你的回答不是比我的更正確或不正確。我只是簡單地指出一種方法,儘可能少地修改OP代碼,以獲得所描述的結果。 –
我正在檢查'cell.value返回null',但正如你所說的那樣,根據它所評估的類型,值會得到掩碼;)謝謝+1 – bonCodigo