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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

wongm003

Board Regular
Joined
Aug 8, 2005
Messages
237
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
 

Forum statistics

Threads
1,136,700
Messages
5,677,277
Members
419,683
Latest member
MrVBAConfused

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
Top