define a range that equals the first row of another range

R

Richard

I want to create my own function that is similar to vlookup, but also uses
match function.

My understanding is that there is no way to embed worksheet functions within
another worksheet function, so I will have to perform the 'match' and
'vlookup' functions separately.

In only want to have to import one lookup range for both the vlookup and
match functions. Since the vlookup range will include the match range, I am
looking for a way to extract the first row.

That is match-range equals first-row-of-vlookup-range.

How can I define a range that equals the first row of another range?
 
M

Mike H

Hi,

You can embed worksheetfunctions in VB and here's an index-match example

myvalue = WorksheetFunction.Index(Range("D1:D15"),
WorksheetFunction.Match(Range("H1"), Range("B1:B15")))

Perhaps you could explain a bit more clearly what you are trying to do and
I'm sure someone will help.

Mike
 
R

Richard

Mike,
You solved first problem I am having with the embeded function.
My Excel book indicated I should use 'application.worksheetfunction' not
just 'worksheetfunction'. The longer expression does not embed.

The problem I'm still having is that I would like to only have to pass one
range through my function, something like this:

sub function modified_vlookup(input_value, search_range, column_heading)
modified_lookup= vlookup(input_value, search_range, match(column_heading,_
first-column-of-search_range)
end function

So you see I still need a way of coming up with
first-column-of-search_range
 
A

Alan Beban

Richard said:
Mike,
You solved first problem I am having with the embeded function.
My Excel book indicated I should use 'application.worksheetfunction' not
just 'worksheetfunction'. The longer expression does not embed.

The problem I'm still having is that I would like to only have to pass one
range through my function, something like this:

sub function modified_vlookup(input_value, search_range, column_heading)
modified_lookup= vlookup(input_value, search_range, match(column_heading,_
first-column-of-search_range)
end function

So you see I still need a way of coming up with
first-column-of-search_range
Application.Index(search_range, 0, 1)

Alan
 
R

Richard

Alan,
Sorry for not being clearer.

Assume I need to do a vlookup and a match statement in the same user defined
function.

If I imput the vlookup_lookup_range (a 2-D) array, I will need either the
first row or first column of vlookup_lookup_range to do the Match function.

So how do I get range for the, say, the first row from vlookup_lookup_range?
 
Joined
Sep 8, 2009
Messages
4
Reaction score
0
LOL Bump but was not answered & I needed it lol


to return first row of range "vlookup_lookup_range"

OFFSET(vlookup_lookup_range,0,0,1,COLUMNS(vlookup_lookup_range))


or if you want to look it up in the header which is row above the range
use

OFFSET(vlookup_lookup_range,-1,0,1,COLUMNS(vlookup_lookup_range))


so
Your answer would be something like

VLOOKUP($A3,vlookup_lookup_range,MATCH("STOCK_ALPHA",OFFSET(vlookup_lookup_range,-1,0,1,COLUMNS(vlookup_lookup_range)),0))


to return the data from the column which has as a header above the range which could come from a query
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top