Excel: how to check if a cell is empty

S

Sameh Ahmed

Hello there
I am using a nested loop to read from an Excel workbook.
When I reach the first unused Cell, an "Object reference not set to an
instance of an object" error is generated.
How do I check if the cell if used or not?
I tried:
xbook.Application.Cells(i, 1).value().ToString.Length <> 0
xbook.Application.Cells(i, 1).value() = Nothing
and both did not work.
Any ideas?
Regards
Sameh
 
M

Mike Walker

Hi Sameh

There is a function called IsEmpty(cell) that returns true or false, this
method is in the VBA.Information object namespace if you are using .NET and
is how I would deal with this problem.

Rgds

Mike Walker
(Reply via NG)
 
S

Sameh Ahmed

Hello Mike
Yes I am using VB .Net
I added a reference to VB for applications, looked for this method and did
not find.
May I am missing something here.
So can you please be kind enough to show me an example?
Thanks in advance.
Sameh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top