Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
On a userform I have 3 commandbuttons - say CB1, CB2,CB3 all send info to different sheets however I'm slipping up sometimes by clicking on the wrong button and sending the info to the wrong sheet is it possible by using a Checkbox to use CB1 and Disable CB2 & CB3 and like wise when necessary Enable CB2 and Disable CB1 and CB3 -- Many Thanks Sue |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could use 3 checkboxes to enable/disable each of the 3 commandbuttons--or
you could use 3 optionbuttons and choose the one checkbox that you want enabled. Or you could just add a prompt to the 3 procedures that do the work: Dim Resp as long resp = inputbox(Prompt:="Are you sure you want to use CB1",buttons:=vbyesno) if resp = vbno then exit sub end if ==== But if you want... I create a small userform with a frame, 3 optionbuttons in that frame and 3 commandbuttons. The frame was named: Frame1 The Optionbuttons were named: OptionButton1, OptionButton2, OptionButton3 The Commandbuttons were named: Commandbutton1, Commandbutton2, commandbutton3 This was the code I used: Option Explicit Private Sub OptionButton1_Click() Call DoTheWork(WhichOne:=1) End Sub Private Sub OptionButton2_Click() Call DoTheWork(WhichOne:=2) End Sub Private Sub OptionButton3_Click() Call DoTheWork(WhichOne:=3) End Sub Private Sub UserForm_Initialize() Dim iCtr As Long With Me For iCtr = 1 To 3 .Controls("Optionbutton" & iCtr).Value = False .Controls("Commandbutton" & iCtr).Enabled = False Next iCtr .Frame1.Caption = "Choose The Commandbutton" End With End Sub Private Sub DoTheWork(WhichOne As Long) Dim iCtr As Long For iCtr = 1 To 3 Me.Controls("Commandbutton" & iCtr).Enabled = CBool(iCtr = WhichOne) Next iCtr End Sub Sue wrote: Hi On a userform I have 3 commandbuttons - say CB1, CB2,CB3 all send info to different sheets however I'm slipping up sometimes by clicking on the wrong button and sending the info to the wrong sheet is it possible by using a Checkbox to use CB1 and Disable CB2 & CB3 and like wise when necessary Enable CB2 and Disable CB1 and CB3 -- Many Thanks Sue -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Mr Peterson
Thank you for your help I used your Frame Solution to good effect works really well -- Many Thanks Sue "Dave Peterson" wrote: You could use 3 checkboxes to enable/disable each of the 3 commandbuttons--or you could use 3 optionbuttons and choose the one checkbox that you want enabled. Or you could just add a prompt to the 3 procedures that do the work: Dim Resp as long resp = inputbox(Prompt:="Are you sure you want to use CB1",buttons:=vbyesno) if resp = vbno then exit sub end if ==== But if you want... I create a small userform with a frame, 3 optionbuttons in that frame and 3 commandbuttons. The frame was named: Frame1 The Optionbuttons were named: OptionButton1, OptionButton2, OptionButton3 The Commandbuttons were named: Commandbutton1, Commandbutton2, commandbutton3 This was the code I used: Option Explicit Private Sub OptionButton1_Click() Call DoTheWork(WhichOne:=1) End Sub Private Sub OptionButton2_Click() Call DoTheWork(WhichOne:=2) End Sub Private Sub OptionButton3_Click() Call DoTheWork(WhichOne:=3) End Sub Private Sub UserForm_Initialize() Dim iCtr As Long With Me For iCtr = 1 To 3 .Controls("Optionbutton" & iCtr).Value = False .Controls("Commandbutton" & iCtr).Enabled = False Next iCtr .Frame1.Caption = "Choose The Commandbutton" End With End Sub Private Sub DoTheWork(WhichOne As Long) Dim iCtr As Long For iCtr = 1 To 3 Me.Controls("Commandbutton" & iCtr).Enabled = CBool(iCtr = WhichOne) Next iCtr End Sub Sue wrote: Hi On a userform I have 3 commandbuttons - say CB1, CB2,CB3 all send info to different sheets however I'm slipping up sometimes by clicking on the wrong button and sending the info to the wrong sheet is it possible by using a Checkbox to use CB1 and Disable CB2 & CB3 and like wise when necessary Enable CB2 and Disable CB1 and CB3 -- Many Thanks Sue -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Enable/Disable Macro | Excel Programming | |||
enable/disable multiple buttons | Excel Discussion (Misc queries) | |||
Enable/Disable CommandBar Buttons Based on Events | Excel Programming | |||
Enable/Disable Macro | Excel Programming | |||
macro disable and enable. | Excel Programming |