Hi, OrionDon!
You don't need VBA for doing that but you can use it. Give a look at this file:
https://dl.dropboxusercontent.com/u/60558749/Dynamic%20find%20using%20variables%20in%20the%20What%20clause.%20%28for%20OrionDon%20at%20chandoo.org%29.xlsm
Formula solution (Hoja4):
a) Search for values, column A in worksheet Sheet1
b) Search into values, column A in worksheet Sheet2
c) Status values, column A:B in worksheet Sheet3
A2: =SI(Hoja1!$A2<>"";Hoja1!$A2;"") -----> in english: =IF(Sheet1!$A2<>"",Sheet1!$A2,"")
B2: =SI(Hoja1!$A2<>"";SI(ESNOD(COINCIDIR(A2;Hoja2!A:A;0));"Not found";"Found");"") -----> in english: =IF(Sheet1!$A2<>"",IF(ISNA(MATCH(A2,Sheet2!A:A,0)),"Not found","Found"),"")
C2: =SI(B2="Found";COINCIDIR(A2;Hoja2!A:A;0);"") -----> in english: =IF(B2="Found",MATCH(A2,Hoja2!A:A,0),"")
VBA solution (Hoja3):
a) Define 3 dynamic named ranges (not necessary but recommended, you can use them in the formula solution version)
SearchForList: =DESREF(Hoja1!$A$1;;;CONTARA(Hoja1!$A:$A);CONTARA(Hoja1!$1:$1)) -----> in english: =OFFSET(Sheet1!$A$1,,,COUNTA(Sheet1!$A:$A),COUNTA(Sheet1!$1:$1))
SearchIntoList: =DESREF(Hoja2!$A$1;;;CONTARA(Hoja2!$A:$A);CONTARA(Hoja2!$1:$1)) -----> in english: =OFFSET(Sheet2!$A$1,,,COUNTA(Sheet2!$A:$A),COUNTA(Sheet2!$1:$1))
StatusTable: =DESREF(Hoja3!$A$1;;;CONTARA(Hoja3!$A:$A);CONTARA(Hoja3!$1:$1)) -----> in english: =OFFSET(Sheet3!$A$1,,,COUNTA(Sheet3!$A:$A),COUNTA(Sheet3!$1:$1))
b) Place this code in any module and run it:
-----
[pre]
Code:
Sub Member_Search_New()
' constants
Const ksWSSearchFor = "Hoja1" '"Sheet1"
Const ksSearchFor = "SearchForList"
Const ksWSSearchInto = "Hoja2" '"Sheet2"
Const ksSearchInto = "SearchIntoList"
Const ksWSStatus = "Hoja3" '"Sheet3"
Const ksStatus = "StatusTable"
' declarations
Dim rngF As Range, rngI As Range, rngS As Range, c As Range
Dim lFor As Long, lInto As Long, lFound As Long, lNotFound As Long
' start
Set rngF = Worksheets(ksWSSearchFor).Range(ksSearchFor)
Set rngI = Worksheets(ksWSSearchInto).Range(ksSearchInto)
Set rngS = Worksheets(ksWSStatus).Range(ksStatus)
With rngS
If .Rows.Count > 1 Then Range(.Rows(2), .Rows(.Rows.Count)).ClearContents
End With
' process
lInto = rngI.Rows.Count - 1
lFound = 0
lNotFound = 0
With rngF
For lFor = 2 To .Rows.Count
Set c = rngI.Find(.Cells(lFor, 1).Value, _
rngI.Cells(1, 1), xlValues, xlWhole, , xlNext, True)
rngS.Cells(lFor, 1).Value = .Cells(lFor, 1).Value
If c Is Nothing Then
lNotFound = lNotFound + 1
rngS.Cells(lFor, 2).Value = "Not found"
Else
lFound = lFound + 1
rngS.Cells(lFor, 2).Value = "Found"
rngS.Cells(lFor, 3).Value = c.Address(False, False)
End If
Next lFor
End With
' end
MsgBox lFor - 2 & " values searched for in " & ksWSSearchFor & "!" & rngF.Address & vbCrLf & _
lInto & " values to search into in " & ksWSSearchInto & "!" & rngF.Address & vbCrLf & _
lFound & " values found in " & ksWSStatus & "!" & rngF.Address & vbCrLf & _
lNotFound & " values found in " & ksWSStatus & "!" & rngF.Address & vbCrLf, _
vbApplicationModal + vbInformation, "Summary"
Set rngS = Nothing
Set rngI = Nothing
Set rngF = Nothing
Beep
End Sub
[/pre]
-----
Just advise if any issue.
Regards!