Sub Find_ID_In_IDColumn()
Dim Forename As String
Dim Surname As Variant
Dim Message, Title, ID
Dim SearchWB As Workbook
Dim IDColFind As Range
Dim ColNum As Long
Dim IDFind As String
Dim lr2 As Long
'Enter Forename (blank Forename is OK)
Forename = Application.InputBox("Enter Forename", "Forename")
ThisWorkbook.Sheets(1).Cells(1, 2) = Forename
'Enter Surname
Do While Not Valid
Surname = Application.InputBox("Enter Surname", "Surname")
If Surname = False Then
Exit Sub
ElseIf Surname = Empty Then
MsgBox "You must enter a Surname"
Valid = False
Else
ThisWorkbook.Sheets(1).Cells(2, 2) = Surname
Valid = True
End If
Loop
'Enter ID (ID List created in Cells(3, 2) using an Excel FILTER function)
Do While Not Valid
ID = Application.InputBox("Enter ID from ID List", "ID")
If ID = False Then
Exit Sub
ElseIf ID = Empty Then
MsgBox "You must enter a ID"
Valid = False
Else
ThisWorkbook.Sheets(1).Cells(3, 2) = ID
Valid = True
End If
Loop
'Open SearchWBs (loops through list in SearchWBPathNames WS2/Column2)
lr2 = ThisWorkbook.Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lr2
SearchWBName = ThisWorkbook.Sheets(2).Cells(i, 1)
SearchWBPathName = "SHAREPOINT PATHNAME/" & SearchWBName
Set SearchWB = Workbooks.Open(SearchWBPathName)
'Find ID column number in SearchWB
With SearchWB.Sheets(1).Rows(1)
Set IDColFind = .Find(What:="ID", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not IDColFind Is Nothing Then
ColNum = IDColFind.Column
End If
End With
'ID to search for
IDFind = ThisWorkbook.Sheets(1).Cells(3, 2)
'Find ID in SearchWB/ID column - if found write SearchWB filename to WS3/Next Row
Filename = ActiveWorkbook.Name
If Trim(IDFind) <> "" Then
With Sheets(1).Columns(ColNum)
Set rng = .Find(What:=IDFind, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Dim lr As Long
lr3 = ThisWorkbook.Sheets(3).Range("A" & Rows.Count).End(xlUp).Row
nr3 = lr3 + 1
If Not rng Is Nothing Then
ThisWorkbook.Sheets(3).Cells(nr3, 1) = Filename
End If
End With
End If
'Close SearchWB (without saving)
SearchWB.Close
Next i
End Sub