لديك اخطاء في تحديد اسماء الخلايا كما في الصورة المرفقة
تم تعديل الكود ليسهل التعامل معه
Private Sub CommandButton2_Click()
'بحث
Dim WS As Worksheet, F As Worksheet
Dim Irow As Long, Clé As String, i As Long
Set WS = Sheets("Sheet2"): Set F = Sheets("Sheet1"): Clé = F.[E3]
Application.ScreenUpdating = False
If Clé = Empty Then: MsgBox "برجاء إدخال اسم للبحث عن بياناته", vbCritical, "فلاح": Exit Sub
Irow = WS.Cells(WS.Rows.Count, "B").End(xlUp).Row
Set rng = WS.Range("B3:B" & Irow).Find(Clé, LookIn:=xlValues, _
lookat:=xlWhole, SearchDirection:=xlPrevious)
If rng Is Nothing Then: MsgBox " الاسم غير موجود", vbExclamation, Clé: Exit Sub
For i = 3 To Irow
If WS.Cells(i, 2) = Clé Then
' Colmun (D)
F.[D5] = WS.Cells(i, "B")
F.[D7] = WS.Cells(i, "C"): F.[D9] = WS.Cells(i, "D"): F.[D11] = WS.Cells(i, "E")
F.[D13] = WS.Cells(i, "F"): F.[D15] = WS.Cells(i, "G"): F.[D17] = WS.Cells(i, "H")
F.[D19] = WS.Cells(i, "I"): F.[D21] = WS.Cells(i, "J"): F.[D23] = WS.Cells(i, "K")
' Colmun (G)
F.[G7] = WS.Cells(i, "L"): F.[G9] = WS.Cells(i, "M"): F.[G11] = WS.Cells(i, "N")
F.[G13] = WS.Cells(i, "O"): F.[G15] = WS.Cells(i, "P"): F.[G17] = WS.Cells(i, "Q")
F.[G19] = WS.Cells(i, "R"): F.[G21] = WS.Cells(i, "S"): F.[G23] = WS.Cells(i, "T")
' Colmun (J)
F.[J7] = WS.Cells(i, "U")
F.[J9] = WS.Cells(i, "V"): F.[J11] = WS.Cells(i, "W")
F.[J13] = WS.Cells(i, "X"): F.[J15] = WS.Cells(i, "Y")
End If
Next
Application.ScreenUpdating = True
End Sub
مع تعديل كود الترحيل بالشكل التالي
Private Sub CommandButton1_Click()
' اظافة
Dim WS As Worksheet: Dim F As Worksheet
Set WS = Sheets("Sheet1"): Set F = Sheets("Sheet2")
Application.ScreenUpdating = False
F.Range("B" & F.Rows.Count).End(xlUp).Offset(1).Resize(, _
24).Value = Application.Index(WS.Range _
("D5,D7,D9,D11,D13,D15,D17,D19,D21,D23,G7,G9,G11,G13,G15,G17,G19,G21,G23,J7,J9,J11,J13,J15"), _
1, 1, Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, _
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26))
With F.Range("A3:A" & F.Cells(Rows.Count, "B").End(xlUp).Row)
.Value = Evaluate("ROW(" & .Address & ")-2")
End With
Lr = F.Range("A65500").End(xlUp).Row
b = F.Cells(2, F.Columns.Count).End(xlToLeft).Column
F.Range(F.Cells(3, 1), F.Cells(Lr, b)).Borders.Weight = xlThin
' افراغ
CommandButton4_Click
Application.ScreenUpdating = True
MsgBox "تم اضافة البيانات بنجاح"
End Sub
123 (1).xlsm