في هذاه الحالة
يلزم هذا الكود
Option Explicit
Private Sub Worksheet_Activate()
Application.EnableEvents = False
fil_data_val
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$A$2" And Target.Count = 1 Then
Call find_Please(Me, Range("a2"))
End If
Application.EnableEvents = True
End Sub
'++++++++++++++++++++++++++++
Sub find_Please(SH As Worksheet, Rg)
Dim Principal As Worksheet
Dim Ro% 'first found row
Dim Ro_Atc% 'All Others found rows
Dim m%: m = 4
Dim My_rg As Range 'find range with Criteria in cell(A2)
SH.Range("A4:E" & Rows.Count).Clear
Set Principal = Sheets("serch")
For Each SH In Sheets
If SH.Name <> Principal.Name Then
Set My_rg = SH.Range("C:C").Find(Rg, lookat:=1)
If My_rg Is Nothing Then GoTo Next_sh
Ro = My_rg.Row: Ro_Atc = Ro
Do
Principal.Cells(m, 1).Resize(, 5).Value = _
SH.Cells(Ro_Atc, 1).Resize(, 5).Value
m = m + 1
Set My_rg = SH.Range("C:C").FindNext(My_rg)
Ro_Atc = My_rg.Row
If Ro_Atc = Ro Then Exit Do
Loop
End If
Next_sh:
Next
If m = 4 Then _
MsgBox "Current Account Not Found": Exit Sub
With Principal.Range("A4:E" & m - 1)
.Borders.LineStyle = 1
.Font.Bold = True
.Font.Size = 24
.HorizontalAlignment = 2
.VerticalAlignment = 2
.Interior.ColorIndex = 24
.InsertIndent 1
End With
End Sub
'++++++++++++++++++++++++++++
Sub fil_data_val()
Dim S As Worksheet, T As Worksheet
Dim dic As Object
Dim i%
Set S = Sheets("serch")
Set dic = CreateObject("Scripting.Dictionary")
For Each T In Sheets
If T.Name = S.Name Then GoTo Next_T
i = 2
Do Until T.Range("c" & i) = vbNullString
dic(T.Range("C" & i).Value) = vbNullString
i = i + 1
Loop
Next_T:
Next T
With S.Range("A2").Validation
.Delete
.Add 3, Formula1:=Application.Transpose(Join(dic.keys, ","))
End With
dic.RemoveAll: Set dic = Nothing
Set T = Nothing: Set S = Nothing
End Sub
الملف مرفق
Search_Account _repetitions.xlsm