Search and return value
One way:
Public Sub FindAnywhere()
Dim vLook As Variant
Dim vMeans As Variant
Dim rFound As Range
Dim i As Long
Dim sTemp As String
vLook = Array("a", "b", "c", "d", "e")
vMeans = Array("apple", "banana", "cherry", _
"dog", "elephant")
For i = 0 To UBound(vLook)
Set rFound = Cells.Find( _
what:=vLook(i), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not rFound Is Nothing Then _
sTemp = sTemp & ", " & vLook(i) & " = " & vMeans(i)
Next i
ActiveCell.Value = Mid(sTemp, 3)
End Sub
Note: this won't prevent overwriting one of the values if the active
cell contains that value.
In article ,
index wrote:
Is it possible to use a macro to search a sheet to find several values
eg, a/b/c/d/e (which could be anywhere on the sheet) and if any of them
are found a message is posted in the active cell stating eg "a =
apples", "b = bananas" with nothing being posted for those not found?
Is this,or anything similar, possible?
Any help would be much appreciated
|