Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Radio Buttons
Hi please bear with me on this as I'm new at this!! I'm trying to work out how to use Radio Buttons with Command Buttons? I have 4 buttons (A,B,C,D, each for a different worksheet ) and Command Buttons (1 to 9 with Names),what code do I need if I click on button (Name) to go to the selected radio button?? Any help appreciated ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com ~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Radio Buttons
Hello GrahamD,
Assume you have 4 options button(radio buttons) named a to d. To make a radio button selected, you need to specity the Worksheet name and the control name like this. Here is acode for CommandButtons. Private Sub CommandButton1_Click() Sheet1.a.Value = True End Sub Private Sub CommandButton2_Click() Sheet2.b.Value = True End Sub -- Kind Regards Colo /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Colo of 'The Road of The Cell Masters' :) URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ "GrahamD" wrote in message ... Hi please bear with me on this as I'm new at this!! I'm trying to work out how to use Radio Buttons with Command Buttons? I have 4 buttons (A,B,C,D, each for a different worksheet ) and 9 Command Buttons (1 to 9 with Names),what code do I need if I click on a button (Name) to go to the selected radio button?? Any help appreciated. ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ ~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Radio Buttons
Thanks for the quick reply Colo. However, I keep getting a "compile error", "Method or data member not found", with the (.a) in the cod highlighted? Confused.. ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com ~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Radio Buttons
OK Graham, the code below makes a sample workbook with VBA code.
Place this code in the standard module and run, then a sample worksheet will be made. Please have a look at code and objects names. Hope this helps. Sub MakeSampleWbk() Dim wbSample As Workbook Dim lngShINW As Long Dim arrNames As Variant Dim strCode As String Dim i As Long arrNames = Array("a", "b", "c", "d") lngShINW = Application.SheetsInNewWorkbook Application.SheetsInNewWorkbook = 4 Set wbSample = Workbooks.Add '//Add Worksheet Application.SheetsInNewWorkbook = lngShINW For i = 1 To 4 '//Add Objects and Make code for CommandButton With wbSample With ..Sheets(i).OLEObjects.Add(ClassType:="Forms.Optio nButton.1", _ Left:=50, Top:=50, Width:=100, Height:=20) .Name = arrNames(i - 1) .Object.Caption = "This name is " & arrNames(i - 1) End With .Sheets(1).OLEObjects.Add(ClassType:="Forms.Comman dButton.1", _ Left:=150, Top:=15 + 30 * i, Width:=120, Height:=30).Name _ = "CommandButton" & i strCode = strCode & _ "Private Sub CommandButton" & i & "_Click()" & vbLf & vbTab & _ "Sheet" & i & "." & "Select" & vbLf & vbTab & _ "Sheet" & i & "." & arrNames(i - 1) & ".Value = True" & vbLf & _ "End Sub" & vbLf & vbLf End With Next With wbSample.VBProject.VBComponents.Item("Sheet1").Cod eModule .DeleteLines 1, .CountOfLines '//Delete Codes already wrriten .InsertLines 1, strCode '// Write Code End With End Sub -- Kind Regards Colo /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Colo of 'The Road of The Cell Masters' :) URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ "GrahamD" wrote in message ... Thanks for the quick reply Colo. However, I keep getting a "compile error", "Method or data member not found", with the (.a) in the code highlighted? Confused... ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ ~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Radio Buttons
Colo, Thanks for your time and trouble, but I must be dumb as. All I kept getting was "Compile Errors" I did however end up working out my problem, although it took som time. This is what I ended up with... Private Sub cmdButton1_Click() If optButton1.Value = True Then Application.Goto Reference:=Worksheets("Sheet1").Range("A1"), _ Scroll:=True End If If optButton2.Value = True Then Application.Goto Reference:=Worksheets("Sheet2").Range("A1"), _ Scroll:=True End If If optButton3.Value = True Then Application.Goto Reference:=Worksheets("Sheet3").Range("A1"), _ Scroll:=True End If If optButton4.Value = True Then Application.Goto Reference:=Worksheets("Sheet4").Range("A1"), _ Scroll:=True End If End Sub ........................................ Private Sub optButton1_Click() End Sub ........................................ Private Sub optButton2_Click() End Sub ........................................ Private Sub optButton3_Click() End Sub ........................................ Private Sub optButton4_Click() End Sub ....................................... CHEERS GRAHA ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com ~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Radio Buttons
Hello GRAHAM, on my Excel your code works.
Please re-check if the object name is correct or not. You can see a sample file at http://www.interq.or.jp/sun/puremis/...oft/Sample.XLS Private Sub cmdButton1_Click() Dim i As Long For i = 1 To 4 If Me.OLEObjects("optButton" & i).Object.Value Then Application.Goto Sheets("Sheet" & i).Range("A1"), True Exit For End If Next End Sub -- Kind Regards Colo /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Colo of 'The Road of The Cell Masters' :) URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ "GrahamD" wrote in message ... Colo, Thanks for your time and trouble, but I must be dumb as. All I kept getting was "Compile Errors" I did however end up working out my problem, although it took some time. This is what I ended up with... Private Sub cmdButton1_Click() If optButton1.Value = True Then Application.Goto Reference:=Worksheets("Sheet1").Range("A1"), _ Scroll:=True End If If optButton2.Value = True Then Application.Goto Reference:=Worksheets("Sheet2").Range("A1"), _ Scroll:=True End If If optButton3.Value = True Then Application.Goto Reference:=Worksheets("Sheet3").Range("A1"), _ Scroll:=True End If If optButton4.Value = True Then Application.Goto Reference:=Worksheets("Sheet4").Range("A1"), _ Scroll:=True End If End Sub ....................................... Private Sub optButton1_Click() End Sub ....................................... Private Sub optButton2_Click() End Sub ....................................... Private Sub optButton3_Click() End Sub ....................................... Private Sub optButton4_Click() End Sub ...................................... CHEERS GRAHAM ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ ~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Radio buttons | Excel Discussion (Misc queries) | |||
Option Buttons/Radio Buttons | New Users to Excel | |||
radio Buttons | Excel Discussion (Misc queries) | |||
Radio Buttons | Excel Worksheet Functions | |||
VBA: Disable Frame and Radio Buttons based on Another Radio Button Being True | Excel Worksheet Functions |