# iterative function

#### excelnovicehouston

##### New Member
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``````

how would i do if I wanted the iterations to be .5 instead of by integer?

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

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``````

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.

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``````

you're a god - VoGod

Replies
5
Views
182
Replies
5
Views
294
Replies
4
Views
384
Replies
18
Views
679
Replies
5
Views
1K

1,220,951
Messages
6,157,030
Members
451,392
Latest member
malcv

### 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.

### Which adblocker are you using?

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

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