here is the module code that is not working, i do have code that is working on a procedure that works ok.
what am i doing wrongPlease Login or Register to view this content.
here is the module code that is not working, i do have code that is working on a procedure that works ok.
what am i doing wrongPlease Login or Register to view this content.
Last edited by dmcgov; 05-24-2021 at 09:11 AM.
making separate posts (as the code is too long for one post). here is the proc code that works perfectly.
Please Login or Register to view this content.
and here is the sample MErrorTest3 module code to test the adderrcode procedure
and here is what it looks like when the code is ran:Please Login or Register to view this content.
what am i doing wrong, or how to fix this?Please Login or Register to view this content.
Last edited by dmcgov; 05-24-2021 at 08:57 AM.
I think your code would be a lot simpler if you used things like Procofline
Your code is flawed since you are trying to alter the end of a For loop from within that loop, which won't work. Have a look at this, and see how many times you think you'll see a message:
If you thought anything other than 1, you're mistaken.Please Login or Register to view this content.
Rory
rory,
I would agree with you that i would only see the msgbox 1 time. but my FOR is dynamic so it reruns the loop when needed. see the following code. it is dynamic. let me know what you think. might need to loop using step -1 but you tell me if there is a better way (a sample of ProcOfLine would be great)
Please Login or Register to view this content.
I feel slightly ill. That kind of thing is exactly why Goto is so frowned upon.
See the 'Listing all procedures in a module' section here: http://www.cpearson.com/Excel/VBE.aspx
so hopefully your over your illness :-) , so the next question is how would you do this? if goto's are frowned upon in loops, what is the best way to accomplish my goal of adding error code to all procs in a module? i did refer to chips site when i was making this sub.
Personally I wouldn't, (if I really wanted to I'd use MZ Tools) but that doesn't really help you.
As with all things in Excel when you are altering the loop, you should loop backwards. Then inserting rows after the point you're at will have no effect on your loop. Alternatively, you can build up a list of the procedures, then just iterate through that using ProcStartLine with the procedure name to find the start of the procedure and do your manipulation that way. Since you're finding the correct position each time, the inserting of lines will have no effect.
thanks rorya, i had to beat it into my head that going forwards was never going to work. got it all sorted out.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks