Radio Buttons

  • Thread starter Thread starter GrahamD
  • Start date Start date
G

GrahamD

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
 
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/colo/CellMastersLink.htm
mailto:[email protected]

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

GrahamD said:
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.


------------------------------------------------



~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements
 
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..
 
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.OptionButton.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.CommandButton.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").CodeModule
.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/colo/CellMastersLink.htm
mailto:[email protected]

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
GrahamD said:
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...


------------------------------------------------



~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements
 
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
 
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/colo/soft/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/colo/CellMastersLink.htm
mailto:[email protected]

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


GrahamD said:
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


------------------------------------------------



~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements
 
Back
Top