== How to test if a range var contains nothing

G

Guest

I need to check if a certain range var is nothing.
Suppose you have the following code

Dim R As Range

If R = Nothing then
End If

When I try to compile this I receive and object error in the If line. Then
how can I test if R has something. Finally IsNull and IsEmpty don´t work too.
Regards
 
M

Myrna Larson

Is Nothing has a specific meaning in VBA, namely that the object variable has
never been set. Is that what you are after? If so, the syntax is

If R Is Nothing Then

OTOH, if you HAVE set R to point to a range, and you want to know whether that
range is empty,

Set R = Range("A1:A250")
If Application.COUNTA(R) = 0 Then
 

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