Private Sub CommandButton1_Click()
Dim ctrl As Control
Dim ligne As Integer
Dim feuille As String
'sélection de la feuille
If Formulairedesaisie.OptionButton1 = True Then feuille = 'Base'
If Formulairedesaisie.OptionButton2 = True Then feuille = 'ROM RCLI VPO50'
If Formulairedesaisie.OptionButton3 = True Then feuille = 'LCR'
If feuille = '' Then
MsgBox 'Merci de sélectionner une feuille.'
Exit Sub
End If
'Enregistrement des données sur la feuille
With Sheets(feuille)
If .Range('A65536').End(xlUp).Row < 3 Then
ligne = 3
Else
ligne = .Range('A65536').End(xlUp).Row + 1
.Cells(ligne, 1) = .Cells(ligne - 1, 1) + 1
End If
' derligne = .Range('a65536').End(xlUp).Row + 1
End With
'pour chaque controle dans l'userform
With Sheets(feuille)
For Each ctrl In Me.Controls
'si la propriété tag n'est pas vide
If Not ctrl.Tag = '' Then
Select Case Val(ctrl.Tag)
Case 1 To 11:
'renvoi txtbox et combobox
If IsNumeric(ctrl) Then
.Cells(ligne, Val(ctrl.Tag)) = CDbl(ctrl)
Else
.Cells(ligne, Val(ctrl.Tag)) = ctrl
End If
'renvoi caption de l'optionbutton si coché sinon vide
Case 12, 13:
If ctrl.Visible = True Then
.Cells(ligne, Val(ctrl.Tag)) = IIf(ctrl, 'X', '')
End If
End Select
End If
Next ctrl
End With
MsgBox 'Votre dossier a été enregistré sous le numéro ' & Sheets(feuille).Range('A2').End(xlDown)
Unload Me
ActiveWorkbook.Save
End Sub