View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Select Case with Nothing

Okay, so if I understand you correctly, you are trying to test whether
DataRange is pointing to a range or not. And, for some reason, you want to
use a Select Case instead of the If-Then test you already know how to do. I
don't think you can do it that way. Well, I guess you could do this...

Select Case True
Case DataRange Is Nothing
......
Case Else
......
End Select

but, personally, I hate using True that way... when you do, the Case
statements are really nothing more than If-Then-Else blocks, so you might as
well use If-Then-Else.

Rick



"J@Y" wrote in message
...
My variables are range variables.
I set them using something like:

Set DataRange = Range("a1", "c1")

I know they can be assigned nothing because I can use

If Not DataRange Is Nothing Then

to test each individual variable


"Rick Rothstein (MVP - VB)" wrote:

I am trying to test multiple variables to see if they have been assigned
nothing.

I tried:

Select Case Nothing

but seems you can't use Nothing like you use True/False.
How would I about this problem?


What is the data type of the variables you are trying to check? If they
are
a numeric data type, VB automatically assigns 0 (in the appropriate data
type) to them at their creation, so you can't test whether a value has
been
assigned to them or not. If they are Strings, then they start life as a
NullString and you can test for this using

If YourStringVariable = vbNullString Then...

If the are Variants, you can test if anything has been assigned to it
using
the IsEmpty function, like this

If IsEmpty(YourVariantVariable) Then...

Rick