Variables not Initialized in Excel VBA Loop

5,390

In VBA you can't use a For Loop on an array with no dimensions defined.

So if your accepted array hasn't been (Re)Dim'ed to have an actual dimension before the Loop starts, you'll get that error.

Check out this StackOverflow question for some ways to deal with (potentially) non-dimensioned arrays:

Share:
5,390

Related videos on Youtube

2012ssohn
Author by

2012ssohn

Updated on September 18, 2022

Comments

  • 2012ssohn
    2012ssohn over 1 year

    I'm back with another question in VBA.

    Here's the (updated) file I'm working on. When I try to run it, it says Run-time error '92': For loop not initialized.

    The loop is For Each var In accepted and I have already defined var and accepted as follows:

    Dim accepted() As Variant

    Dim var As Variant

    ...

    For Each var In accepted

    ...

    Next var

    I'm not sure why this error is occurring.