Option Explicit
Private WS As Worksheet
Private LR As Long
Private Sub UserForm_Initialize()
Set WS = ThisWorkbook.Worksheets("الملاك")
LR = WS.Cells(Rows.Count, 2).End(xlUp).Row
End Sub
Private Sub CommandButton1_Click()
If TextBox1 = "" Then MsgBox "عفوا يجب ادخال الرمز", vbExclamation: TextBox1.SetFocus: Exit Sub
If Application.WorksheetFunction.CountIf(WS.Range("b2:b" & LR), TextBox1) > 0 Then _
MsgBox "عفوا هذا الرمز موجود", vbInformation: Exit Sub
With WS
.Range("b" & LR + 1).Value = TextBox1.Value
.Range("c" & LR + 1).Value = TextBox2.Value
.Range("d" & LR + 1).Value = TextBox3.Value
.Range("e" & LR + 1).Value = TextBox4.Value
.Range("f" & LR + 1).Value = TextBox5.Value
MsgBox "تمت الاضافة بنجاح"
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
End With
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CommandButton3_Click()
CommandButton3.Caption = WS.Range("b" & LR)
End Sub
Private Sub CommandButton4_Click()
Dim C As Range
With WS
For Each C In .Range("b2:b" & LR)
If C Like TextBox6.Value & "*" Then
.Cells(C.Row, 2).Value = TextBox1.Text
.Cells(C.Row, 3).Value = TextBox2.Text
.Cells(C.Row, 4).Value = TextBox3.Text
.Cells(C.Row, 5).Value = TextBox4.Text
.Cells(C.Row, 6).Value = TextBox5.Text
.Cells(C.Row, 7).Value = ComboBox1.Value
.Cells(C.Row, 8).Value = TextBox8.Text
.Cells(C.Row, 9).Value = TextBox9.Text
.Cells(C.Row, 10).Value = TextBox10.Text
.Cells(C.Row, 11).Value = TextBox11.Text
End If
Next C
End With
MsgBox "نم تعديل البيانات بنجاح"
Call TextBox6_Change
End Sub
Private Sub TextBox6_Change()
For Each Cel In WS.Range("b2:b" & LR)
If (Val(Me.TextBox6)) = Cel Then
Me.TextBox1 = Cel.Offset(0, 0)
Me.TextBox2 = Cel.Offset(0, 1)
Me.TextBox3 = Cel.Offset(0, 2)
Me.TextBox4 = Cel.Offset(0, 3)
Me.TextBox5 = Cel.Offset(0, 4)
Me.ComboBox1 = Cel.Offset(0, 5)
Me.TextBox8 = Cel.Offset(0, 6)
Me.TextBox9 = Cel.Offset(0, 7)
Me.TextBox10 = Cel.Offset(0, 8)
Me.TextBox11 = Cel.Offset(0, 9)
End If
Next
End Sub