The following vba code can't be executed in Excel vba. Why?
Please Login or Register to view this content.
The following vba code can't be executed in Excel vba. Why?
Please Login or Register to view this content.
Last edited by tommycho; 05-26-2015 at 10:20 AM.
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.
Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.
Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
Why do you think it should work?The following vba code can't be executed in Excel vba. Why?
p(1) and p(2) are two independent variables like i and j, i don't understand why it doesn't work,
Edit your first post and wrap the code with the code tag.
It's a MUST forum rule.
First post edited. Can anyone help?
If you understand above line of your code, you should realize why it will not work.Please Login or Register to view this content.
Your code doesn't make sense anyway.
This declares p(2) as a single (array) variable,
if you try that code you'll get a For control variable in use compile error - p(1) and p(2) are elements of the same variable.Please Login or Register to view this content.
Last edited by Norie; 05-26-2015 at 10:30 AM.
If posting code please use code tags, see here.
Thanks Norie for the explanation. So p(1) and p(2) aren't independent variables but are elements of the same variable. Am my understanding correct?
Your code is fine but for the fact that VBA doesn't allow the use of array elements as the control variables in a for/next loop.
Dim p(2) is equivalent to Dim p(0 to 2) (or Dim p(1 to 2) if you use Option Base 1)
Entia non sunt multiplicanda sine necessitate
shg
You can use an array element as the loop control variable - try the OP's code without the inner loop.
Sorry, I meant you can't use them in nested loops. I learned that by trying a couple of years ago -- it would have been convenient.
It seems like an odd restriction.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks