View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Using a vlookup to search multiple criteria for one result?

Hi,

Am Tue, 12 Mar 2013 16:15:53 +0000 schrieb srm6:

This worked perfectly. However, when I put it
into my spreadsheet consisting of 19804 rows it bogged down the report
and took forever for me to run the existing macro I have in the report.
Is there a way to add this to an existing macro so it will run faster?


that is the disadvantage of array formulas in more than 500 rows.
Try it with VBA:

Sub Test()
Dim LRow As Long
Dim i As Long
Dim rngC As Range
Dim firstAddress As String

With Sheets("Sheet1")
LRow = .Cells(.Rows.Count, 2).End(xlUp).Row
For i = 2 To LRow
Set rngC = Sheets("Sheet2").Range("A1:A20000").Find _
(.Cells(i, 2), LookIn:=xlValues)
firstAddress = rngC.Address
Do
If rngC.Offset(0, 1) = .Cells(i, 3) Then
.Cells(i, 1) = rngC.Offset(0, 2)
End If
Set rngC = Sheets("Sheet2").Range("A1:A20000").FindNext(rngC)
Loop While Not rngC Is Nothing And rngC.Address < firstAddress
Next
End With
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2