VB code to replace HLOOKUP

MarcusEd

New Member
Joined
Jan 15, 2019
Messages
3
Hello

Being new and unfamiliar with the possibilities of VB in Excel, I’m hoping someone could help me with a solution to some code I’ve been trying to write.

Basically there are three tables:

First table is an input table that will extend down for several hundred rows eventually but I’ve limited to just a couple for the example,
A reference table
An output table – this used to be an HLOOKUP table but this has become too cumbersome and I’ve run out of arguments in the formula, hence resorting to code instead.

Basically starting with each row of data in the input table, need to reference the value of each successive column to the corresponding date row in the reference table. Then put the resultant date in the output table.

For example refer Input table cell E2 (7,000), refers to the reference table will return this value occurs in Aug 19 which is then returned in the output table.

I need the code to loop through multiple rows of the input table and returning the corresponding date value in the output table.

Many thanks.

Input table 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th
Row1 1000 3000 5000 7000 9000 11000 13000 15000 17000 19000
Row2 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000


Reference table Jan-19 Feb-19 Mar-19 Apr-19 May-19 Jun-19 Jul-19 Aug-19 Sep-19 Oct-19 Nov-19 Dec-19 Jan-20 Feb-20 Mar-20 Apr-20
Row 1 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000

Output table 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th
Row1 Feb-19 Apr-19 Jun-19 Aug-19 Oct-19 Dec-19 Feb-20 Apr-20 Jun-20 Aug-20
Row2 Jun-19 Nov-19 Apr-20 Sep-20
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
With the limited data you have shown this can be done with a simple formula


Excel 2013/2016
ABCDEFGHIJKLMNOPQ
1Input table1st2nd3rd4th5th6th7th8th9th10th
2Row1100030005000700090001100013000150001700019000
3Row25000100001500020000250003000035000400004500050000
4
5
6Reference tableJan-19Feb-19Mar-19Apr-19May-19Jun-19Jul-19Aug-19Sep-19Oct-19Nov-19Dec-19Jan-20Feb-20Mar-20Apr-20
7Row 10100020003000400050006000700080009000100001100012000130001400015000
8
9Output Table1st2nd3rd4th5th6th7th8th9th10th
10Row1Feb-19Apr-19Jun-19Aug-19Oct-19Dec-19Feb-20Apr-20
11Row2Jun-19Nov-19Apr-20
Today
Cell Formulas
RangeFormula
B10=IFERROR(INDEX($B$6:$Q$6,MATCH(B2,$B$7:$Q$7,0)),"")


Copy formula down & across
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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