Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test for empty range 2

Status
Not open for further replies.

Johnny42

Technical User
Jul 13, 2004
127
CA
I'm setting FR as a range.
How can I test to see if the range is null ?
 

Here is one way:
Code:
Sub DemoEmptyRange()
Dim r As Range
  Set r = Intersect(Range("A1:B2"), Range("C3:D4"))
  If r Is Nothing Then
    MsgBox "r is null"
  Else
    MsgBox r.Address
  End If
End Sub

 
Hi Johnny,

Zathras is absolutely correct. Nothing is as close to Null as Excel gets. I suspect, given the title however, that you may want to check for the cells in the range all being empty - if so, here is one way ...
Code:
[blue]Set FR = Range("A1:X10") [green]' Perhaps[/green]
If Evaluate("=COUNTA(" & FR.Address & ")") = 0 Then
    MsgBox "Range is empty"
Else
    MsgBox "Range is not empty"
End If[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top