جرب هذا الكود
ليس عليك لا ان تكتب رقم الطالب واكسل يتكفل بالباقي (بعد الضغط على زر ترحيل)
CODE
Option Explicit
Sub test()
Dim x, y, D As Worksheet, O As Worksheet
Dim c As Range, s As String, cnt As Long
Dim Ro_Out As Range, Ro_In As Range
Dim F_rg As Range
Dim F_date As Range
Dim Claer_rg As Range
Set D = Sheets("data")
Set O = Sheets("Output")
Set Ro_Out = O.Range("A8:A" & O.Cells(Rows.Count, 1).End(xlUp).Row)
Set Ro_In = D.Range("A8:A" & D.Cells(Rows.Count, 1).End(xlUp).Row)
Ro_In.Offset(, 1).Resize(, 2).ClearContents
Set Claer_rg = O.Range("D7:AH7").Find(D.Range("d1"), lookat:=1)
If Claer_rg Is Nothing Then
MsgBox "This Date Not Exists": Exit Sub
Else
y = Claer_rg.Column
O.Cells(8, y).Resize(1000).ClearContents
End If
For Each c In Ro_In.Cells
'********************************
Set F_rg = Ro_Out.Find(c, lookat:=1)
If F_rg Is Nothing Then
MsgBox "No data For cells:" & c.Address(0, 0)
GoTo Next_C
Else
cnt = cnt + 1
x = F_rg.Row
O.Cells(x, y) = "X"
c.Offset(, 1) = O.Cells(x, 2)
c.Offset(, 2) = O.Cells(x, 3)
End If
Next_C:
Next c
If cnt > 0 Then
MsgBox "That is ALL " & cnt, vbInformation
End If
End Sub
الملف مرفق