السلام عليكم
استبدل الكود السابق بهذا
Private Sub CommandButton3_Click()
Dim T As Integer, i As Integer
If Val(Label5) And OptionButton1.Value = True Then
For i = 1 To Val(Label5)
Label5.Caption = Val(Label5) - 1
With Sheets("Sheet1")
Endrow = .Range("A1").CurrentRegion.Rows.Count
.Cells(Endrow + 1, 1).Value = Endrow
.Cells(Endrow + 1, 2).Value = TextBox1.Value
.Cells(Endrow + 1, 3).Value = TextBox2.Value
.Cells(Endrow + 1, 4).Value = TextBox3.Value
.Cells(Endrow + 1, 5).Value = TextBox4.Value
End With
Next
ClerMe
For T = 2 To 3
If Val(Me.Controls("Label" & T + 4)) > 0 Then Me.Controls("OptionButton" & T) = True: Exit Sub
Next
End If
'=======================================
If Val(Label6) And OptionButton2.Value = True Then
For i = 1 To Val(Label6)
Label6.Caption = Val(Label6) - 1
With Sheets("Sheet1")
Endrow = .Range("A1").CurrentRegion.Rows.Count
.Cells(Endrow + 1, 1).Value = Endrow
.Cells(Endrow + 1, 2).Value = TextBox1.Value
.Cells(Endrow + 1, 3).Value = TextBox2.Value
.Cells(Endrow + 1, 4).Value = TextBox3.Value
.Cells(Endrow + 1, 5).Value = TextBox4.Value
End With
Next
ClerMe
If Val(Label7) > 0 Then OptionButton3.Value = True: Exit Sub
End If
'====================================================
If Val(Label7) And OptionButton3.Value = True Then
For i = 1 To Val(Label7)
Label7.Caption = Val(Label7) - 1
With Sheets("Sheet1")
Endrow = .Range("A1").CurrentRegion.Rows.Count
.Cells(Endrow + 1, 1).Value = Endrow
.Cells(Endrow + 1, 2).Value = TextBox1.Value
.Cells(Endrow + 1, 3).Value = TextBox2.Value
.Cells(Endrow + 1, 4).Value = TextBox3.Value
.Cells(Endrow + 1, 5).Value = TextBox4.Value
End With
Next
ClerMe
If Val(Label5) Then OptionButton1.Value = True: Exit Sub
If Val(Label6) Then OptionButton2.Value = True: Exit Sub
End If
End Sub
Sub ClerMe()
For i = 1 To 4
Me.Controls("TextBox" & i) = Clear
Next
End Sub