بعد اذن الاستاذ محمد الدسوقي
اختصار بسيط للكود الذي تفضلتم بتقديمه
CODE
Private Sub CommandButton1_Click()
Dim rng As Range, ws As Worksheet, lr As Long
Dim RgC As Range, RgK As Range, rgS As Range
Dim RgAA As Range, RgAI As Range, m%
Dim OptionaL_rg As Range
Dim bol As Boolean
Set ws = Sheets("Data")
Set RgC = ws.Range("C300").End(xlUp).Offset(1, 0)
Set RgK = ws.Range("K300").End(xlUp).Offset(1, 0)
Set rgS = ws.Range("S300").End(xlUp).Offset(1, 0)
Set RgAA = ws.Range("AA300").End(xlUp).Offset(1, 0)
Set RgAI = ws.Range("AI300").End(xlUp).Offset(1, 0)
For i = 1 To 6
If Controls("TextBox" & i).Value = "" Then
bol = True
Exit For
End If
Next i
If bol Then
MsgBox ("من فضلك ادخل بيانات الحقول الفارغة"), _
64, "أكاديمية الصقر للتدريب"
Exit Sub
End If
bol = False
For i = 1 To 5
Select Case Me.Controls("OptionButton" & i)
Case True: m = i: GoTo my_m
End Select
Next
my_m:
If m = 0 Then
MsgBox ("لم يتم اختيار القسم"), 64, _
"أكاديمية الصقر للتدريب"
Exit Sub
End If
Select Case m
Case 1: Set OptionaL_rg = RgC
Case 2: Set OptionaL_rg = RgK
Case 3: Set OptionaL_rg = rgS
Case 4: Set OptionaL_rg = RgAA
Case 6: Set OptionaL_rg = RgAI
End Select
OptionaL_rg.Offset(0, -2).Value = OptionaL_rg.Row - 2
With OptionaL_rg
For i = -1 To 4
.Offset(0, i) = Me.Controls("TextBox" & i + 2).Value
Next
End With
'------------------------------------------------
MsgBox ("تم ترحيل البيانات ... بنجاح"), 64, _
"أكاديمية الصقر للتدريب"
Clear_All
End Sub
'++++++++++++++++++++++++++++++++++++
Private Sub UserForm_Initialize()
Clear_All
End Sub
'++++++++++++++++++++++++++++++++++
Private Sub Clear_All()
For i = 1 To 6
If i <= 5 Then
Controls("OptionButton" & i).Value = False
End If
Me.Controls("Textbox" & i).Value = ""
Next i
End Sub
الملف مرفق