# Need help: after processing a loop for getting the max value, how do we get the variants corresponding to the max value?

#### dylan32123

##### New Member
here is the detail of what am doing and what i want to achieve, thx a lot for your help!

[FONT=arial, courier new, courier, 宋体, monospace, Microsoft YaHei]dim a1 as variant
dim b1 as variant
dim a2 as variant
dim b2 as variant
dim c as variant
dim maxC as variant

for a1 = 0 to 250 step 5
for a2 = 0 to 250 step 5
b1 = calculation with a1
b2 = calculation with a2
if c > maxC then
maxC = c
end if
next a2
next a1

after using this loop how can we get the value of a1 & a2 when the maxC reached?

thx again
[/FONT]

### Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

#### Tetra201

##### MrExcel MVP
Try this (not tested):
Code:
``````......
If c > maxC Then
maxC = c
maxC_a1 = a1
maxC_a2 = a2
End If
......``````

Last edited:

Replies
0
Views
401
Replies
0
Views
435
Replies
10
Views
436
Replies
5
Views
651
Replies
17
Views
415

1,195,628
Messages
6,010,770
Members
441,568
Latest member
abbyabby

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