Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Trapping error with dynamic range

I have a dynamic range on my worksheet that expands (or contracts) to include
the data in a column. I have VBA code that utilizes this dynamic range. But
if there is no data in the column, the code generates an error ... apparently
there is no range object at all in this case. Other than general error
trapping methods, is there a more direct way to test whether the dynamic
range exists?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Trapping error with dynamic range

"ArthurJ" wrote in message
...
I have a dynamic range on my worksheet that expands (or contracts) to
include
the data in a column. I have VBA code that utilizes this dynamic range.
But
if there is no data in the column, the code generates an error ...
apparently
there is no range object at all in this case. Other than general error
trapping methods, is there a more direct way to test whether the dynamic
range exists?


Hi Arthur,

Here's one way to do it:

Dim rngTest As Range

On Error Resume Next
Set rngTest = Sheet1.Range("MyDynamicRange")
On Error GoTo 0

If Not rngTest Is Nothing Then
''' There is data in the dynamic range.
End If

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Thanks Rob. (eom)



"Rob Bovey" wrote:

"ArthurJ" wrote in message
...
I have a dynamic range on my worksheet that expands (or contracts) to
include
the data in a column. I have VBA code that utilizes this dynamic range.
But
if there is no data in the column, the code generates an error ...
apparently
there is no range object at all in this case. Other than general error
trapping methods, is there a more direct way to test whether the dynamic
range exists?


Hi Arthur,

Here's one way to do it:

Dim rngTest As Range

On Error Resume Next
Set rngTest = Sheet1.Range("MyDynamicRange")
On Error GoTo 0

If Not rngTest Is Nothing Then
''' There is data in the dynamic range.
End If

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Trapping error with dynamic range

Rob (or anyone),

I don't understand this line:

On Error GoTo 0


"Rob Bovey" wrote:

"ArthurJ" wrote in message
...
I have a dynamic range on my worksheet that expands (or contracts) to
include
the data in a column. I have VBA code that utilizes this dynamic range.
But
if there is no data in the column, the code generates an error ...
apparently
there is no range object at all in this case. Other than general error
trapping methods, is there a more direct way to test whether the dynamic
range exists?


Hi Arthur,

Here's one way to do it:

Dim rngTest As Range

On Error Resume Next
Set rngTest = Sheet1.Range("MyDynamicRange")
On Error GoTo 0

If Not rngTest Is Nothing Then
''' There is data in the dynamic range.
End If

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trapping error with dynamic range

' ignore any errors
On Error Resume Next
Set rngTest = Sheet1.Range("MyDynamicRange")
' go back to breaking on errors (reset error handling to normal)
On Error GoTo 0


--
Regards,
Tom Ogilvy


"ArthurJ" wrote in message
...
Rob (or anyone),

I don't understand this line:

On Error GoTo 0


"Rob Bovey" wrote:

"ArthurJ" wrote in message
...
I have a dynamic range on my worksheet that expands (or contracts) to
include
the data in a column. I have VBA code that utilizes this dynamic

range.
But
if there is no data in the column, the code generates an error ...
apparently
there is no range object at all in this case. Other than general error
trapping methods, is there a more direct way to test whether the

dynamic
range exists?


Hi Arthur,

Here's one way to do it:

Dim rngTest As Range

On Error Resume Next
Set rngTest = Sheet1.Range("MyDynamicRange")
On Error GoTo 0

If Not rngTest Is Nothing Then
''' There is data in the dynamic range.
End If

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm





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
Error referencing linked dynamic range Basil Links and Linking in Excel 3 January 9th 10 01:48 PM
Defind Dynamic named Range up to first error chg Excel Worksheet Functions 3 December 6th 09 09:32 PM
#value! error trying to create a simple dynamic named range Janis Excel Discussion (Misc queries) 1 August 3rd 07 07:20 PM
error trapping [email protected] Excel Programming 2 January 20th 05 10:07 PM
Error trapping Luis Excel Programming 1 November 11th 04 03:25 AM


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