Trapping error with dynamic range

A

ArthurJ

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?
 
R

Rob Bovey

ArthurJ said:
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
 
A

ArthurJ

Rob (or anyone),

I don't understand this line:

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
 
T

Tom Ogilvy

' 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top