Address of the return value of hlookup

varan

New Member
Joined
Sep 19, 2016
Messages
17
Hello,
Im trying to obtain the cell address of the value returned by hlookup and then transfer another value to the cell below it. In the code month_match returns a string. I've defined Mat_add as Range. I get [h=1]Application-defined or object-defined error, Office 1004[/h]error code. Wanted to know what is the mistake in my command?

VB:

Month_match = Application.WorksheetFunction.HLookup(Month, Blad1.Range("B8:N9"), 1, False)
Mat_add = Application.WorksheetFunction.Index(ThisWorkbook.ActiveSheet.Range("B9:N9"), Application.WorksheetFunction.Match(Month_match, ThisWorkbook.ActiveSheet.Range("B8:N9"), 0), 1)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Application.WorksheetFunction.Match(Month_match, ThisWorkbook.ActiveSheet.Range("B8:N9"), 0), 1)

The lookup_array for MATCH needs to refer to a one-dimensional array, e.g. B8:B9 or B9:N9.

Regards
 
Upvote 0
I've defined Mat_add as Range.

Although it is true that INDEX is capable of returning a cell reference as well as a cell value, you cannot achieve this simply by declaring Mat_add as a Range.

Try removing this declaration, which should return the cell value, rather than cell reference, and then we can work from there.

Unfortunately there are several more problems with your code, primarily with your use of worksheet functions. For example, in:

Application.WorksheetFunction.Index(ThisWorkbook.ActiveSheet.Range("B9:N9")...

you are passing a range of just a single row (B9:N9) to INDEX, so the only value for the row_num parameter which would not result in an error is 1.

Which means that, unless:

Application.WorksheetFunction.Match(Month_match, ThisWorkbook.ActiveSheet.Range("B8:N9"), 0)

results in a 1, your INDEX makes no sense whatsoever.

I'm afraid that's not the only issue, but I think we need to start with the declaration of Mat_add to begin with.

Regards
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top