Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default How to Improve my "Vlookup" on Steroids function.....

I'd like to know if there is a way to speed up the following function because
I use it ALOT on larger source ranges.

This function is similar to Vlookup except:
Instead of passing the value in column 1 and a column number...
You pass the String representing the title of up to 3 columns-
DataCol = Column with data you want to retrieve.
Col1 = Column to filter by
Col2 = a second column to filter by
If there are multiple findes, it flags the answer

Here's an example.....

"TextA" "TextB" "TextC"
1 3 Z
1 4 X
1 4 Y
2 4 X
3 4 L

X2Find(range, "TextC", "TextA", 1, "TextB", 3) = "Z"
X2Find(range, "TextB", "TextA", 1, "TextC", "X") = 4
X2Find(range, "TextC", "TextA", 1, "TextB", 4) = "!! 2 Matches !!"


Function X2Find(rngTemp As Range, DataCol As Variant, Col1Title As Variant,
Col1Val As Variant, Col2Title As Variant, Col2Val As Variant)
'THIS FUNCTION is like VLookup except you:
' Provide 2 column Titles and search values...
'
'Range = with Titles
'DataCol = column you want the data from
'Col1Val = First Column Test
'Col1Title = First Column Title
'Col2Val = Second Column Test
'Col2Title = Second Column Title


rRows = rngTemp.Rows.Count
rCols = rngTemp.Columns.Count
foundCol1 = False
foundCol2 = False
foundall = False

For c = 1 To rCols
If rngTemp(1, c) = DataCol Then
DataCol = c
foundData = True
foundall = foundall + 1
End If
Next c
For c = 1 To rCols
If rngTemp(1, c) = Col1Title Then
Col1Title = c
foundCol1 = True
foundall = foundall + 1
End If
Next c
For c = 1 To rCols
If rngTemp(1, c) = Col2Title Then
Col2Title = c
foundCol2 = True
foundall = foundall + 1
End If
Next c

If foundall < 3 Then
X2Find = "Missing Info"
Exit Function
End If

foundrows = False
For r = 1 To rRows
testval1 = rngTemp(r, Col1Title)
testval2 = rngTemp(r, Col2Title)
If testval1 = Col1Val And testval2 = Col2Val Then
foundrows = foundrows + 1
lastmatchingrow = r
End If
Next r

Select Case foundrows
Case False
X2Find = "No Match"
Case 1
X2Find = rngTemp(lastmatchingrow, DataCol)

Case Is 1
X2Find = "!! " & foundrows & " Matches !!"

End Select

End Function

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text "comparison" operator for "contains" used in an "IF" Function Pawaso Excel Worksheet Functions 4 April 4th 23 11:35 AM
Excel crashes when typing "false" in VLookup function pcbins Excel Worksheet Functions 18 January 30th 09 09:24 PM
correct syntax for nesting "if", "and", and "vlookup"....if possib Christine Excel Worksheet Functions 4 January 2nd 09 10:43 PM
Please add a "sheet" function like "row" and "column" functions Spreadsheet Monkey Excel Programming 2 November 8th 05 04:08 PM
IF(VLOOKUP("MYDATA", MYNAME, 4) = 0, "TRUE", "FALSE") Souris Excel Programming 2 August 17th 05 05:33 AM


All times are GMT +1. The time now is 08:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"