Hi.
This is the first time I've ever tried building/using a userform and it turns out it's not as easy as I'd expected. Can anyone help?
I've set things up so that when my "Main" macro is initiated, it immediately opens up a userform "MyForm" so the user can enter values into the 2 text boxes & decide (via checkbox "Chk1") if they want to run the "Secondary" macro before "Main".
If the user presses the CANCEL button, the form is (ideally) supposed to close not only "MyForm" but also "Main" too. But if they press the RUN button, it should either (a) hide itself, and then run "Secondary" (if checked) before running "Main", using the values in "Box1" & "Box2" as variables in "Main", (b) hide itself, and then run "Main" using the values in "Box1" & "Box2" as variables, or (3) if applicable, return a message box saying they've forgotten to enter data or entered an invalid number.
And to get really fancy (tho it's definitely not necessary), I'd love it if the text boxes could, say, refer back to cells F7 & F9 in "Sheet1" as their default value (since users can also enter values directly into the sheet itself) but that, if the user entered numbers into the form, those values would replace the ones on the sheet. Not only would it mean that you wouldn't have to refer back to the sheet to see what your last setting were, but "Main" is now set up to take the values from the sheet (e.g. the variable iNum1 is set to cell F7) and I'd rather not force users to use the form if they'd prefer to work directly off the sheet. Understand?
But right now the contents of "Box1" & "Box2" aren't actually used by "Main"; "Chk1" works but it runs "Secondary" immediately.. even before I press RUN; CANCEL returns a 'Type Mismatch' error, and the whole "MyForm" stays visible while "Main" runs which is annoying b/c it's a huge macro & can take minutes or even hours depending on the number of loops required.
I've read up on how to write userform code & spent lots of time reading forum postings on the subject, but I'm still pretty lost. Here's what I have so far...
"Main" contains this code after all the Dim's:
And then the "MyForm" code contains all of this (sorry for how long it is):
So where am I going wrong???
Bookmarks