+ Reply to Thread
Results 1 to 18 of 18

userform to select option button without running the code that's in it

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    userform to select option button without running the code that's in it

    Hello everyone.
    I have a userform with various option buttons and when any option button is selected the corresponding code enters info on an excel chart depending on which button was selected. The user then can reopen the userform and will see the option button that was previously selected automatically selected via "userform initialize" (i.e. OptionButton1 = True).
    The issue i am having is that as soon as the userform starts up it actually executes the option button and in my case causes errors because i only wanted the option button to run once in the first time the userform is opened. in this case the useform is running it a second time when the userform is opened a second time. How can i tell the code to mark the option button as true but not execute it?

    Looking forward to any responses

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: userform to select option button without running the code that's in it

    Hi kosherboy

    One approach would be, once the Option Button is clicked, disable it.
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    Thanks jaslake,
    The issue really lies when the userform is initialized, once the the userform is open the user can selected/deselect the option button without any errors being caused.

  4. #4
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    Let me elaborate:
    When i plugged in your idea the code was still running the code in the option button.
    How can i have the userform mark the optionbutton value as true without running its code?
    Last edited by kosherboy; 04-22-2015 at 12:47 PM.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: userform to select option button without running the code that's in it

    You need to use a control variable that the optionbutton code checks before running its own code.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    I hear. How can i do that?

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: userform to select option button without running the code that's in it

    How/why is the option button being selected when the userform opens?

    Is it linked to a cell?
    If posting code please use code tags, see here.

  8. #8
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    Please Login or Register  to view this content.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: userform to select option button without running the code that's in it

    At the top of the form module :
    Please Login or Register  to view this content.
    Then the first line of the optionbutton code needs to be:
    Please Login or Register  to view this content.
    And wherever you need to change the value without running the code, you use:
    Please Login or Register  to view this content.
    for example.

  10. #10
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    Hi romperstomper,
    I did as you suggested but it seems the code is still executing.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: userform to select option button without running the code that's in it

    What happens if you remove the posted code from the form's Initialize event?

  12. #12
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    Which part of the code are you referring to Norie that you want removed?

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: userform to select option button without running the code that's in it

    Quote Originally Posted by kosherboy View Post
    Hi romperstomper,
    I did as you suggested but it seems the code is still executing.
    That isn't possible if you did what I said. Please post the entire code you used.

  14. #14
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    Userform initialize:
    Please Login or Register  to view this content.
    executes when option button is selected:
    Please Login or Register  to view this content.
    Is called from the code which executes from the option button
    Please Login or Register  to view this content.
    Last edited by kosherboy; 04-22-2015 at 03:26 PM.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: userform to select option button without running the code that's in it

    Please Login or Register  to view this content.
    This line should be at the top of the module outside any procedures, and nowhere else.

  16. #16
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    I feel kinda funny asking this at this point in the game as i should know this by now but what do you mean outside the module? I understand publicly decalring variables but then i use the "Public" instead of "Dim".

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: userform to select option button without running the code that's in it

    I mean at the top of the module, before any private sub routines.

  18. #18
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: userform to select option button without running the code that's in it

    Wow! I applaud you!
    I am also very thankful to you for helping solve the issue.
    Best of luck to you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. UserForm Option Button Help...
    By z-eighty2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2013, 10:17 PM
  2. Userform option button help
    By mecharissa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2012, 04:48 AM
  3. Replies: 0
    Last Post: 07-18-2012, 09:45 AM
  4. Userform Option Button to Show/Hide Another Option Button on same Userform
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2010, 09:44 AM
  5. Select option button when have the name as a string
    By Debbie Probert via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2005, 01:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1