ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Best way to check if cell is empty?? (https://www.excelbanter.com/excel-programming/437789-best-way-check-if-cell-empty.html)

Robert Crandal

Best way to check if cell is empty??
 
I currently use the following code to test if a cell is empty:

If IsEmpty(Sheet1.Range("A1").Value) then
' code here
End If

Are there better or other ways to check if a cell is empty???
Also, does it matter if I put the ".Value" at the end of the
Range("A1") code?

thankx




Dave Peterson

Best way to check if cell is empty??
 
You don't need the .value, but then you're relying on the default property for
that range (which is .value).

The same way you don't need the .value he

activesheet.range("A1") = "hi there"

Personally, I think it's much better to include the property--I think it
documents the code better.

And that's the way I'd check to see if the cell were really empty.

If you only cared about what you saw in the cell (a formula could evaluate to
""), you could use:

if sheet1.range("a1").value = "" then

But that really doesn't test for emptiness.

Robert Crandal wrote:

I currently use the following code to test if a cell is empty:

If IsEmpty(Sheet1.Range("A1").Value) then
' code here
End If

Are there better or other ways to check if a cell is empty???
Also, does it matter if I put the ".Value" at the end of the
Range("A1") code?

thankx


--

Dave Peterson


All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com