Why is Cell not an object

W

WhytheQ

Morning All,

Philosophical rather than practical question - I'm auditing all my
code and trying to be as explicit as possible with my variable
declarations. So really trying to avoid using Variant. I use the
following structure quite a bit:

Dim myCell
For Each myCell In .Sheets("Static").Range("xxx").Cells
If myCell <> "" Then
'code to execute here on each cell if cell not empty
End If
Next

myCell is a variant but I'd prefer to declare it as a specific data
type or object so that the code is more precise.

Any help appreciated
Jason.
 
D

Dave Peterson

I'm not sure if I understand your question, but I'd use:

Dim myCell as Range

And I'd be explicit:
if mycell.value <> "" then
or
if isempty(mycell.value) then

A cell containing a formula evaluating to "" would satisfy the first condition,
but not the second.

And a cell containing that formula that was converted to a value would behave
the same!
 

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