empty range

  • Thread starter Thread starter ranswert
  • Start date Start date
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
 
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
 
If application.counta(r) > 0 then
msgbox "at least one cell is non-empty"
else
msgbox "all empty"
end if
 
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
 
Back
Top