iterative function

excelnovicehouston

New Member
Joined
Feb 5, 2009
Messages
44
I am looking for how to set up a iterative function that returns the max value for example

function maxit(a)

For b = 10, 11, 12, 13

value&"_"&b = b* a + -b^2 +3

maxit = application.max(value_10, value_11, value_12, value_13)

end function

Many thanks for any help on the language around this
I am only looking for the discreet values 10,11,12,13 not a range in between them.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Function maxit(a)
Dim b As Integer, y As Double
For b = 10 To 13
    y = b * a + -b ^ 2 + 3
    If y > maxit Then maxit = y
Next b
End Function
 

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,432
Hi

If you are seeking the maximum value as a result of the formula in your post, then that will be your highest input value wouldn't it? If b is constant then the highest value of a will return the highest resultant value, and vice versa. If both a na db a reinput values, then the highest resultant value would be with the highest values of a and b, given -b^2 = b^2.

Andrew
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

Try

Code:
Function maxit(a)
Dim b As Double, y As Double
For b = 10 To 13 Step 0.5
    y = b * a + -b ^ 2 + 3
    If y > maxit Then maxit = y
Next b
End Function
 

excelnovicehouston

New Member
Joined
Feb 5, 2009
Messages
44
Many thanks for the help VoG, my original post was a little off - I want it to display b, that maximizes y, not the y value.

Andrew, many thanks for your help. i am aware that in this simple quadratic the max will be 13, but it is only for illustrative purpose. i am using a much more complex equation that i didn't want to type.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Function maxit(a)
Dim b As Double, y As Double, z As Double
For b = 10 To 13 Step 0.5
    y = b * a + -b ^ 2 + 3
    If y > z Then
        z = y
        maxit = b
    End If
Next b
End Function
 

Forum statistics

Threads
1,136,326
Messages
5,675,122
Members
419,551
Latest member
thangxpm

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
Top