Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Using Nothing and Null

What should be used with range variables if they are empty - IsEmpty(r) or r
is Nothing? Provided that r is declared as Range?
What is the best way to check if range contains no cells, for example list
on worksheet contains only coulumns headers?
Currently I use both techniques - either Set r = Nothing and later test if r
Is Nothing then...or r = Null and later test if IsEmpty(r) then...
Thanks
Mike510


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Using Nothing and Null

If r is a multicell range, then you won't want to use isempty(). That refers to
a single cell.

dim r as range
set r = activesheet.range("a1:b3")

if application.counta(r) = 0 then
'all empty
else
'not all empty
end if

And checking to see if a range is nothing usually means that it hasn't been
assigned a range yet or you've tried to assign it to something that doesn't
exist.

Dim r1 As Range
Dim r2 As Range

Set r1 = ActiveSheet.Range("a1:b3")
On Error Resume Next
Set r2 = r1.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If r2 Is Nothing Then
MsgBox "no formulas in " & r1.Address
Else
MsgBox "formulas found in: " & r2.Address
End If


Mikhail wrote:

What should be used with range variables if they are empty - IsEmpty(r) or r
is Nothing? Provided that r is declared as Range?
What is the best way to check if range contains no cells, for example list
on worksheet contains only coulumns headers?
Currently I use both techniques - either Set r = Nothing and later test if r
Is Nothing then...or r = Null and later test if IsEmpty(r) then...
Thanks
Mike510


--

Dave Peterson

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
Failed to save table attributes of (null) into (null). Luca Brasi Excel Discussion (Misc queries) 2 February 4th 09 04:30 PM
COUNTIF says Null = Blank but Blank < Null Epinn Excel Worksheet Functions 4 October 25th 06 08:03 PM
if a1 = null then a1 = b1...how do I do this? tomas Excel Discussion (Misc queries) 1 April 19th 06 06:04 PM
cell value based on null/not null in another cell spence Excel Worksheet Functions 1 February 18th 06 11:49 PM
Using Nothing and Null Mikhail Excel Programming 1 September 30th 03 10:15 AM


All times are GMT +1. The time now is 01:34 PM.

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"