Option button in a frame return different value

Solved
Lili -  
 Lili -
Hello,

I am working on a time management form project. I have created a form with a frame that contains 3 option buttons (I am a beginner in VBA)
the user has the choice between the first button corresponding to full time, the second to part-time weekly reduction, and the last to part-time daily reduction.

Depending on the selected button, I want the value returned in an Excel sheet to be TP for full time, Redh for weekly reduction, and Redj for daily reduction (which is different from the caption value of each button recorded initially).

At first, my code looked like this

Private Sub Commandbutton1_Click() temp = "" For Each c In Me.Frame1.Controls If c.Value = True Then temp = c.Caption End If Next c Sheets("Effectifs").Cells(Ligne, 7) = temp End Sub


which works very well, but the returned values are: Full time (instead of TP), weekly reduction (instead of Redh)...

After searching a bit, I understood that I needed to incorporate the following lines

 Private Sub Frame1_Click() If OptionButton1.Value = True Then temp = "TP" If OptionButton2.Value = True Then temp = "Redh" If OptionButton3.Value = True Then temp = "RedJ" End If End Sub


but I have no idea where to put them, and it doesn't work :(

I am sure I am almost there, but I need a little help please.

Thank you very much

Configuration: Windows / Internet Explorer 11.0

3 answers

félix
 
Hello Lili,
Excel 2007 file: https://mon-partage.fr/f/tIU1LzBw/
Alt F11 to view the macro, then return to Excel
Best regards
0
pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 772
 
Hello,

Two choices.

1- you want to keep your command button to validate:
Private Sub CommandButton1_Click() With Sheets("Effectifs") Select Case True Case OptionButton1: .Cells(Ligne, 7) = "TP" Case OptionButton2: .Cells(Ligne, 7) = "Redh" Case OptionButton3: .Cells(Ligne, 7) = "RedJ" End Select End With End Sub


2- you can do without the button:
Private Sub OptionButton1_Click() If OptionButton1 Then Sheets("Effectifs").Cells(Ligne, 7) = "TP" End Sub Private Sub OptionButton2_Click() If OptionButton2 Then Sheets("Effectifs").Cells(Ligne, 7) = "Redh" End Sub Private Sub OptionButton3_Click() If OptionButton3 Then Sheets("Effectifs").Cells(Ligne, 7) = "RedJ" End Sub


As you prefer...

--
Best regards,
Franck
0
Lili
 
Hello,

Thank you both for your quick response.
Pikaju, that’s exactly what I wanted; I opted for the first solution, which works perfectly. Thank you very much.

Have a good day.
0