Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Passing Null Value to Range Property

I am setting a range ojbect to a specific range:

Set Rng1 = ActualUsedRange

ActualUsedRange is a public function which returns a range by selected
certain cells in a sheet. Now I know that when I am in a blank worksheet the
VBA UsedRange property as displayed in the Immediate Window comes up empty"

?Worksheets("Sheet1").UsedRange

There are instances where I will not have a range to pass to Rng1 above via
my ActualUsedRange function. For example in a blank worskeet. What error
handling do need to put in so that the following line of code will not fail.
The way I am currently doing it, I get a Runtime Error 424 Object Required.

For Each Cell In Rng1

Thanks

EM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Passing Null Value to Range Property

Hi. here's one way:


If Not Rng1 Is Nothing Then
For Each Cell In Rng1
Next
End If


--
Hope that helps.

Vergel Adriano


"ExcelMonkey" wrote:

I am setting a range ojbect to a specific range:

Set Rng1 = ActualUsedRange

ActualUsedRange is a public function which returns a range by selected
certain cells in a sheet. Now I know that when I am in a blank worksheet the
VBA UsedRange property as displayed in the Immediate Window comes up empty"

?Worksheets("Sheet1").UsedRange

There are instances where I will not have a range to pass to Rng1 above via
my ActualUsedRange function. For example in a blank worskeet. What error
handling do need to put in so that the following line of code will not fail.
The way I am currently doing it, I get a Runtime Error 424 Object Required.

For Each Cell In Rng1

Thanks

EM

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Passing Null Value to Range Property

Isn't UsedRange always at least one cell, even in an empty worksheet.

Anyways, how about

If Not Rng1 Is Nothing Ten

Foe Each Cell In Rng1

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"ExcelMonkey" wrote in message
...
I am setting a range ojbect to a specific range:

Set Rng1 = ActualUsedRange

ActualUsedRange is a public function which returns a range by selected
certain cells in a sheet. Now I know that when I am in a blank worksheet
the
VBA UsedRange property as displayed in the Immediate Window comes up
empty"

?Worksheets("Sheet1").UsedRange

There are instances where I will not have a range to pass to Rng1 above
via
my ActualUsedRange function. For example in a blank worskeet. What error
handling do need to put in so that the following line of code will not
fail.
The way I am currently doing it, I get a Runtime Error 424 Object
Required.

For Each Cell In Rng1

Thanks

EM



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Passing Null Value to Range Property

?Worksheets("Sheet1").UsedRange
is the same as:
?Worksheets("Sheet1").UsedRange.Value

If the sheet is empty, the .usedrange.address will be $A$1. And printing the
value of that single cell will show an empty string.

(If there is more than one cell in the usedrange, then that line will fail.)

You may want to use:
set rng1 = actualusedrange
if rng1.address = "$A$1" then
if isempty(rng1.value) then
msgbox "the sheet is empty"
end if
end if





ExcelMonkey wrote:

I am setting a range ojbect to a specific range:

Set Rng1 = ActualUsedRange

ActualUsedRange is a public function which returns a range by selected
certain cells in a sheet. Now I know that when I am in a blank worksheet the
VBA UsedRange property as displayed in the Immediate Window comes up empty"

?Worksheets("Sheet1").UsedRange

There are instances where I will not have a range to pass to Rng1 above via
my ActualUsedRange function. For example in a blank worskeet. What error
handling do need to put in so that the following line of code will not fail.
The way I am currently doing it, I get a Runtime Error 424 Object Required.

For Each Cell In Rng1

Thanks

EM


--

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
Passing several parameters to OnAction property. LABKHAND Excel Discussion (Misc queries) 1 April 24th 09 08:02 PM
Get Property value of class instance by passing string property name [email protected] Excel Programming 2 October 19th 07 05:47 PM
Property Let: assign return value of Double when passing String Tetsuya Oguma Excel Discussion (Misc queries) 1 March 3rd 06 08:01 AM
Some worksheet returns NULL for CodeName property. Why? Shigeo Morita Excel Programming 4 December 3rd 04 11:09 PM
Passing null to a function Andy Excel Programming 5 November 1st 04 05:49 PM


All times are GMT +1. The time now is 02:13 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"