Index-Match in vba

pjkaphlen

Board Regular
Joined
Aug 3, 2015
Messages
85
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Dear VBA wizards

I have a problem that I need some help from one of you.

I have a table that contains prices and names (dynamic). The names are in columns and the prices are given in rows. Their range changes in every excel workbook. i.e. In WB1, I have 2 names and under each name i have 2 prices. While in WB2 i have 4 Names and under each name I have one price each. Let's try the table below

ABCDE
1MinJohnOlgaPeterName
2$1.5$2.00$1.5$3.0
3$0.5$0.5$1.0$0.75

<tbody>
</tbody>

Here's the trick: on E2 is use this formula "=index($B$1:$D$1,match(A2,B2:D2,0)) to return the name of the person with min. dollar value.

But now I want to create a vba code that can automatically input this formula.

Kindly note that since the number of name changes thus changing the position of the column with "Name" header.

Can anyone enlighten me on this?

Thank you so much in advance!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
you can use variable in formula. for example, instead of r2c2, you can use
r2c" & t & "
t is the column index of r2c2
you can use vba to define the column index before apply it in the vba formula.
 
Last edited:
Upvote 0
you can use variable in formula. for example, instead of r2c2, you can use
r2c" & t & "
t is the column index of r2c2
you can use vba to define the column index before apply it in the vba formula.

Thanks for the idea ww4612!
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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