Results 1 to 2 of 2
2012-06-18, 15:47 #1
- Join Date
- Mar 2002
- San Jose, California, USA
- Thanked 0 Times in 0 Posts
Zero vs. blank cell check in VBA for Excel
I have an excel spreadsheet that can have a number of rows with a zero in column 10 ("quantity") and some rows with text subheaders where the quantity cell is BLANK.
I'm trying to develop a macro to delete the rows where the quantity cell is zero but it also deletes the subheader row. It seems to me that the simple test I'm doing does not discriminate between zero and blank.
If Worksheets(1).Cells(lnRowCount, 10) = 0 Then
Is there a better check method to do this. I guess a couple of nested IFs might work:
If Isblank then skip else if zero then delete.
Is there a more elegant way?
2012-06-18, 17:10 #2
- Join Date
- Mar 2004
- Manning, South Carolina
- Thanked 1,455 Times in 1,324 Posts
Try this code:
Option Explicit Sub ZeroBlank() Dim lCntr As Long For lCntr = 1 To 4 If Cells(lCntr, 1) = 0 Then If Cells(lCntr, 1) = "" Then Debug.Print "Cell Row A" & Format(lCntr, "#") & " is BLANK" Else Debug.Print "Cell Row A" & Format(lCntr, "#") & " = ZERO" End If End If Next lCntr End Sub