Array "defined"???

jcagle

New Member
Joined
Mar 4, 2003
Messages
2
In VBA, is there a way to tell if an array as been ReDim'd somewhere along the line? For example:

Dim Array() as Variant

If (a > b) then
ReDim Array(3)
End If

If (defined(Array)) then
' Do some stuff
End If

Thanks in advance!!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You can use the Ubound function... if the array has been ReDim it will return the upper index...

Code:
Public Sub array_test()
'if an error occurs ignore error and continue
On Error resume Next

    Dim Ar() as Variant 

    If (a > b) then 
        ReDim Ar(3) 
    End If 

    'Note if a subscript was not assigned to the array an
    'error (9) will be triggered.

    If Ubound(Ar)=3 then 
        ' Do some stuff 
    End If
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top