Name previously referenced in this scope

You declared a variable in an outer scope. You then referred to this variable in an inner scope and then declared it in that scope. For example:

Dim X As Integer
Sub MySub
   X% = 5
   Dim X As Integer   ' Illegal because the preceding assignment
                      ' statement referred to the X declared in
                      ' outer scope
End Sub

Move the declaration of the variable in the inner scope so that it precedes the assignment statement, or remove the declaration of the variable in the inner scope. Moving the declaration of the variable in the inner scope creates a local variable that shadows the one in the outer scope, while removing the declaration lets you refer to the variable in the outer scope from within the inner scope.