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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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