-
VBA Loop Control Variable Issue / Question
The code below fails to compile and generates a "For control variable already in use" error on the second for loop. The entire test program is here. The loop works if for example the inner and outer loops have var names such as i and n, but while array(1) and array(2) are separate variable locations the compiler seems to be treating the array name as the single specific variable.
The reason I want to have a loop control variable as an element of an array is because I am writing code that can allow a dynamic number of for loops. I am certain I have used compilers that have allowed this in the past but I suspect no dice with VBA. If there is a switch or other trick that allows this I would be very grateful.
Error generated on second loop where comment is placed.
TIA, Paul
btw, this is not a work related issue, I am simply a hobbiest and have been coding for fun since the late '70's
Option Explicit
Sub TestForLoopVariableName()
Dim LCV(2) As Integer
For LCV(1) = 1 To 10
For LCV(2) = 1 To 10 'for control variable already in use
counter =counter+!
Next LCV(2)
Next LCV(1)
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules