Checking for empty

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I check for emptiness by typing this into the immediate window:

Code:
?IsEmpty(Sheet1.Cells(1,1).Value)

and it returns False

But when I type:

Code:
?Len(Sheet1.Cells(1,1).Value

I get a value of 0!

Can someone tell me what is going on?

Is the worksheet corrupt?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi, have you checked in different sheet ?
 
Upvote 0
The IsEmpty function is designed to test if a data variable has been initialized, and not to check if a cell is blank. (although many people use it for checking if a cell is blank). The best way to check if a cell is blamn is to see if its value equal nullstring (""). Here is the spec sheet link for your edification.
IsEmpty function (Visual Basic for Applications) | Microsoft Docs
 
Upvote 0
Seems it's taking it as Null String. What is the result of below code:

Excel Formula:
MsgBox IsNull(Sheet1.Cells(1, 1).Value)
 
Upvote 0
The IsEmpty function is designed to test if a data variable has been initialized, and not to check if a cell is blank. (although many people use it for checking if a cell is blank). The best way to check if a cell is blamn is to see if its value equal nullstring (""). Here is the spec sheet link for your edification.
IsEmpty function (Visual Basic for Applications) | Microsoft Docs
Thanks.

The real reason for all this is I want to check how many non blank cells in a particular row.

By eye, it looks like 3 but when I type:

Code:
?application.WorksheetFunction.CountA(rows(1))

I get more than 3.

So I proceeded to inspect each cell in that row.

I tried your suggestion and typed:

Code:
?wksq4.Cells(1,7).value=vbnullstring

and it returned True.

I did the same for all remaining cells in row 1 and they all returned True, so how can:

Code:
?application.WorksheetFunction.CountA(rows(1))

return anything other than 3?
 
Upvote 0
If there is a formula in the cell that produces a nullstring as one of its options when all other oprions fail, and you test with IsEmpty, you will get the False return.
But if you test for the length of the value in the cell, you will get zero because Len only checks for displayed values and not for formulas.
 
Upvote 0
If there is a formula in the cell that produces a nullstring as one of its options when all other oprions fail, and you test with IsEmpty, you will get the False return.
But if you test for the length of the value in the cell, you will get zero because Len only checks for displayed values and not for formulas.
so what should I do?
 
Upvote 0
I tried a "trick".

As I said, I can only see values in columns A, B and C.

So on cell A1, I pressed Ctrl+right arrow and it jumped to cell C1, which I interpret to mean cell D1 is blank.

Now on cell C1, I press Ctrl+right arrow and now it jumps to cell G1, which I interpret to mean cells D, E and F are blank but G isn't.
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,664
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top