Dynamic Array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I tell if an array declared initially as myArray() has yet been ReDim'ed?
 
Dan,

You can test the lower or upper bound and trap the error that
occurs if the array isn't dim'd. E.g,

Dim N As Long
On Error Resume Next
N = LBound(Arr,1)
If Err.Number = 9 Then
Debug.Print "Arr not dim'd"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


dan said:
How can I tell if an array declared initially as myArray() has
yet been ReDim'ed?
 
Thanks Chip - already coded that I was hoping for a more elegant solution - oh wel

Thanks again
 
I won't speak to "more elegant", but if the functions in the freely
downloadable file at http://home.pacbell.net are available to your
workbook, here is a different way:

Dim myArray()
'. . . .
MsgBox ArrayDimensions(myArray)

This will display the number of dimensions; 0 if it has not yet been
dimensioned.

Alan Beban
 
Just another idea then...

Sub Demo()
Dim v As Variant
' etc
If Not IsArray(v) Then ReDim v(1 To 10)
End Sub
 
OP wrote
--How can I tell if an array declared initially as myArray() has yet
been ReDim'ed?


Dana said:
Just another idea then...

Sub Demo()
Dim v As Variant
' etc
If Not IsArray(v) Then ReDim v(1 To 10)
End Sub

If it has been ReDim'ed (e.g., 1 to 5) then this code won't disclose that.

Alan Beban
 

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

Back
Top