#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default empty range

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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default empty range

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

--
Gary''s Student - gsnu200770
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default empty range

That works
Thank You

"Gary''s Student" wrote:

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

--
Gary''s Student - gsnu200770

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default empty range

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



ranswert wrote:

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


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default empty range

ranswert wrote:
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Last Empty Row in Range dunnerca Excel Programming 2 January 4th 08 08:00 PM
Range ... how to know if it is empty [email protected] Excel Programming 3 January 30th 06 03:23 PM
Finding next empty empty cell in a range of columns UncleBun Excel Programming 1 January 13th 06 11:22 PM
Range empty? Sige Excel Programming 18 September 23rd 05 02:16 PM
why is range empty? JT Excel Discussion (Misc queries) 1 March 9th 05 12:26 PM


All times are GMT +1. The time now is 10:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"