View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dan R. Dan R. is offline
external usenet poster
 
Posts: 220
Default Looking up data in a large sheet

A formula would be the easiest way but if you need a macro try this:

Sub Test()
Dim i As Range, iEnd As Long, iRng As Range
Dim found1 As Variant, found2 As Variant

With Sheets(1)
iEnd = .Cells(Rows.Count, 1).End(xlUp).Row
Set iRng = .Range(.Cells(1, 1), .Cells(iEnd, 1))
End With

For Each i In iRng
Set found1 = Sheets(2).Range("A1:IV1").Find( _
i.Value, LookIn:=xlValues)
If found1 Is Nothing Then
i.Offset(0, 3) = "Not Found"
Else
With Sheets(2)
ActCol = Mid$(found1.Address, 2, 1) & ":" & _
Mid$(found1.Address, 2, 1)
End With

Set found2 = Sheets(2).Range(ActCol).Find( _
i.Offset(0, 1).Value, LookIn:=xlValues)

If found2 Is Nothing Then
i.Offset(0, 3) = "Not Found"
Else
i.Offset(0, 3) = "Found"
End If
End If
Next i

End Sub

--
Dan Oakes