Trying to add radio buttons to an existing form

HDfatboy03

Board Regular
Joined
May 23, 2010
Messages
62
Hello

I am trying to add several radio buttons. 3 groups of 3 ... grouped as follows: The worksheet is named "CoursesDB" that's where I would like the information to go to.

combobox1 contains:
fh1 - if checked need info going to (iRow, 42) ... value to = 1 or 0
ml1 - if checked need info going to (iRow, 60) ... value to = 1 or 0
mri - if checked need info going to (iRow, 79) ... value to = 1 or 0
combobox2 contains:
fh2 - if checked need info going to (iRow, 43) ... value to = 1 or 0
ml2 - if checked need info going to (iRow, 61) ... value to = 1 or 0
mr2 - if checked need info going to (iRow, 80) ... value to = 1 or 0
combobox3 contains:
fh3 - if checked need info going to (iRow, 44) ... value to = 1 or 0
ml3 - if checked need info going to (iRow, 62) ... value to = 1 or 0
mr3 - if checked need info going to (iRow, 81) ... value to = 1 or 0

I am reading Excel 2007 Power Programming with VBA ... they make it sound so simple and here is the code they are suggesting ... but I can't seem to get it to work.

If FH1 Then Cells(iRow, 42).Value = "1"
If MR1 Then Cells(iRow, 60).Value = "1"
If ML1 Then Cells(iRow, 79).Value = "1"


'the clear command
Me.FH1.Value = ""
Me.MR1.Value = ""
Me.ML1.Value = ""

Any assistance will be greatly appreciated.

Thanks in advance

Bob
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
What is the code you have sofar? Each button will be linked to a subroutine.
 
Upvote 0
This is what I have so far ... Just like the example in the book ... but its not working

'transfer the data
If FH1 Then Cells(iRow, 42).Value = "1"
If MR1 Then Cells(iRow, 60).Value = "1"
If ML1 Then Cells(iRow, 79).Value = "1"

'the clear command
Me.FH1.Value = ""
Me.MR1.Value = ""
Me.ML1.Value = ""

The book makes it look so simple ... but its not close is it ???

thanks

Bob
 
Upvote 0
Bob

Is it comboboxes or option boxes you are working with?
 
Upvote 0
Bob

Do you mean you have 3 group boxes each with 3 option buttons inside each?
 
Upvote 0
Bob

How did you try the code that doesn't work?

When do you actually want the values transferred to the worksheet?

What's iRow?

Sorry for all the questions but I think you might not have posted all the relevant code.:)
 
Upvote 0
Sorry for the delay ... went out of town for a few days. Below is the code for the form that is working ... I just want to add radio buttons.

Private Sub UserForm_Click()
Private Sub cmdAdd3_Click()
Dim iRow As Long
Dim ws, ws2 As Worksheet
'Dim ws As Worksheet
Set ws = Worksheets("CoursesDB")
Set ws2 = Worksheets("CurDB")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a Course Name"
Exit Sub
End If
'copy the data to the databases
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws2.Cells(4, "C").Value = Me.txtPart.Value

'START radio buttons for Fairway H E R E
'copy the NEW DATA Fairway Hit to database
'If FH1 Then Cells(iRow, 42).Value = "1"

'D E L E T E T H E F O R M STARTS HERE
'clear the data
Me.txtPart.Value = ""

'clear the NEW DATA Fairway Hit
Me.FH1.Value = ""

Me.txtPart.SetFocus
End Sub

Thanks in advance for your assistance

Bob
 
Upvote 0
1. Option buttons have the value TRUE or FALSE, not ""

2. The line where you check the value of FH1 is commented out

3. Don't take shortcuts, although the default property is .Value, write it out to make your code more readable and easier to debug:
if FH1.value = True then

4. What is this orphan Private Sub UserForm_Click() doing at the top of your code?

5. If you post code, use the code tags (click on the # button in the formatting icon strip of the post window, or surround your piece of code with [code ] ... [/code ] (without the space)
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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