Excel or VBA code to compare variable against column of figures & perform a function

Charlie4

New Member
Joined
Nov 22, 2017
Messages
9
Hi All

Take a look at the example table below.

RowAgeAge Multiple
1170.8
2201.0
3251.15
4351.20
5501.22
6701.23

<tbody>
</tbody>

Agex
Age x Age Multiple?

<tbody>
</tbody>

If I have a variable "Age" on the sheet (populated from a UserForm) I need excel to look down Age column until it finds the right age range, multiply that age by the value in the Age Multiple Column and return that value.


For example if Age = 40, it should look down the Age column till it gets to row 4 (for ages between 35-50), multiply by the Age Multiple for that group (1.2) and return the result (48).


What is the correct VBA or excel code for this? A for/next loop?


(the actual table is a lot larger and the function more complicated than a simple multiplication)


Many thanks for any help!


Kind regards
Charlie
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi.

Let's assume your table is laid out so that the word "AGE" is in cell A1, the number 15 is in cell A2, the multiple 0.8 is in cell B2, and so on.
Let's assume your input number of 40 is contained in cell C1.

=C1*VLOOKUP(C1,A2:B7,2,TRUE)
 
Upvote 0
Hi.

Let's assume your table is laid out so that the word "AGE" is in cell A1, the number 15 is in cell A2, the multiple 0.8 is in cell B2, and so on.
Let's assume your input number of 40 is contained in cell C1.

=C1*VLOOKUP(C1,A2:B7,2,TRUE)

Gerald - that's perfect. Exactly what I'm looking for.
Many thanks.
C.
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,665
Members
449,462
Latest member
Chislobog

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