Button Selection

kakiebos

Board Regular
Joined
Jun 10, 2018
Messages
62
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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
When you say "buttons" are you referring to "Option Buttons"?
 
Upvote 0
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"
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top