empty range

R

ranswert

How do I write a procedure to look at a range of cells, and if all the cells
are empty do one thing, or if at least on cell in the range has something in
it do something else?

I tried

Sub a()
Dim r As Range
Set r = Range("rng")
r.Select
If r is empty Then
MsgBox ("nothing")
Else
MsgBox ("something")
End If
End Sub

That doesn't seem to work.
Thanks
 
G

Gary''s Student

Sub emptcheck()
For Each r In Selection
If IsEmpty(r) Then
Else
MsgBox ("at least on cell in this range has content")
Exit Sub
End If
Next
MsgBox ("the cells in this range are empty")
End Sub
 
D

Dave Peterson

If application.counta(r) > 0 then
msgbox "at least one cell is non-empty"
else
msgbox "all empty"
end if
 
A

Alan Beban

ranswert said:
How do I write a procedure to look at a range of cells, and if all the cells
are empty do one thing, or if at least on cell in the range has something in
it do something else?

It depends on what you mean by "empty". The suggestions of both Gary's
Student and Dave Peterson will treat as not empty an empty string; i.e.,
the contents of a cell into which you type the formula =""

Alan Beban
 

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