Results 1 to 9 of 9

Thread: Button Selection
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2018
    Location
    South Africa
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Button Selection

    Hi all.

    I have a user form with two buttons for a selection by the user. It is either the one or the other. You can not select both.
    If you select Mobile then the word "Mobile" is to be in cell M1. If you select In Shop then the text "In Shop" is to appear in cell M1. If no button is selected then M1 is to be blank ("")

    I'm not familiar with the select case statements and this one below is not working as I want it to. Are there anyone out there to help me. I will appreciate it.

    Code:
    Select Case Where
        Case Me.btInShop.Value = True And Me.btMobile.Value = True
          Range("M1").Value = ""
        Case Me.btInShop.Value = False
          Range("M1").Value = "In Shop"
        Case Me.btMobile.Value = False
          Range("M1").Value = Mobile
        End Select

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Button Selection

    When you say "buttons" are you referring to "Option Buttons"?
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    New Member
    Join Date
    Jun 2018
    Location
    South Africa
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Button Selection

    Quote Originally Posted by Fluff View Post
    When you say "buttons" are you referring to "Option Buttons"?
    No I have used command buttons.

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Button Selection

    In that case I would suggest using Option Buttons as that's what they are designed for.
    Either that or you simply put this in the Click event for the relevant button
    Code:
    Range("M1").Value = "In Shop"
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  5. #5
    New Member
    Join Date
    Jun 2018
    Location
    South Africa
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Button Selection

    Sorry it is not a command button. I have used a toggle button.

    I prefer not to use the option buttons for aesthetic reasons. I created code for the toggle buttons to work as option buttons in the click event.
    Unless I can make the option buttons to look like two toggle buttons (I don't like the small dot)


    Code:
    Private Sub btInShop_Click()
      If Me.btInShop.Value = True Then
        Me.btMobile.Value = False
      End If
    End Sub
    
    
    Private Sub btMobile_Click()
      If Me.btMobile.Value = True Then
        Me.btInShop.Value = False
      End If
    End Sub
    There are quite a few such options that the user must choose between one of two options. The user also don't have to always choose one of the options. Then the target cell need to stay blank, but if the toggle button is selected, the relevant name are to be entered into the target cell.
    For example two toggle buttons, one is "In Shop" and the other is "Mobile". If the user select "In Shop", then cell M1 must have the text In Shop. If the user select "Mobile", then cell M1 must have the text Mobile. If no selection is made, then cell M1 must be blank

    That is why I thought that the Select Case option would work nicely in the Add button code.

  6. #6
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Button Selection

    You are making life very awkward for yourself using this sort of approach.
    Certain objects have specific rolls & for what you want that is option buttons
    Whilst you may not like the aesthetics of option buttons, I would recommend you use them.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  7. #7
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Button Selection

    If you insist on Toggles try
    Code:
    Private Sub CommandButton1_Click()
       If Me.ToggleButton1 = True Then
          Range("M1") = "inshop"
       ElseIf Me.ToggleButton2 = True Then
          Range("M1") = "mobile"
       Else
          Range("M1") = ""
       End If
    End Sub
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  8. #8
    New Member
    Join Date
    Jun 2018
    Location
    South Africa
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Button Selection

    Thanks.
    That is working for me.

  9. #9
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Button Selection

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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