+ Reply to Thread
Results 1 to 12 of 12

Userform - make sure optionbutton and listbox has values

  1. #1
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Userform - make sure optionbutton and listbox has values

    Hi,

    I have a userform with 2 option buttons, 1 listbox and 2 command buttons. The command buttons are "OK" and "Cancel". I want to make sure that a click on the OK-button generates a msgbox if any of the 2 option buttons or the listbox havent got any value. I cant get this to work, anyone who can help me?

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Userform - make sure optionbutton and listbox has values

    Please Login or Register  to view this content.
    haven't tested in Excel, but should work.
    Last edited by nathansav; 06-04-2013 at 03:20 AM.

  3. #3
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Userform - make sure optionbutton and listbox has values

    Hi,

    Thanks for trying to help me out.

    There are two things im wondering about.

    1 If i click the OK-button inside the msgbox i want to go back to the user form to fill in one of the optionbuttons. How do I do that?
    2 How do i also add so its ensured that the Listbox also is "marked", ie if not marked i want the same msgbox to appear.

    Once again thanks for the help!

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Userform - make sure optionbutton and listbox has values

    Please Login or Register  to view this content.
    I think, not able to test at mo.

  5. #5
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Userform - make sure optionbutton and listbox has values

    Hi again,

    Unfortunately it didnt do the trick...It returns a compile error (freely translated: Cant find the method or data member)

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Userform - make sure optionbutton and listbox has values

    sorry me.ListBox1.ListIndex <> -1

    You can use code posted, if incorrect to further your own search to learn more.

  7. #7
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Userform - make sure optionbutton and listbox has values

    Hi again,

    Thanks for putting in an effort and trying to help a newbie out! My search to learn more starts here im afraid casue i cant make it work with this code

    Please Login or Register  to view this content.

    Anyone else who has an idea?

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Userform - make sure optionbutton and listbox has values

    If (Not Me.OptionButton1 And Not Me.OptionButton2) Or Me.ListBox1.ListIndex = -1 Then

    Just logic

  9. #9
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Userform - make sure optionbutton and listbox has values

    Thank you very much nathansav!

    Now the msgbox appears when it should. (An interesting thing is that it slowed the macro down a bit, cant figure why, but it works so its a small, small problem... or problem...its rather just...interesting)

    How can i make it so if i click the okbutton in the msg box that displays i go back to the userform to fill in whats missing of the option buttons or the listbox?

  10. #10
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Userform - make sure optionbutton and listbox has values

    exit sub, see the answer to your 2nd post. You need to do a bit yourself

  11. #11
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Userform - make sure optionbutton and listbox has values

    Cant you please take a flight here and write "exit sub" in my code while i go get me some coffe? ;-)

    I didnt noticed that when i was trying to make the other thing work. Sorry about that.

    Thank you for all the help!

  12. #12
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Userform - make sure optionbutton and listbox has values

    booked and packed, see you soon

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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