Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A program that will return the cell address of the minimum value in a row?

So I have a chart that looks something like this. Assume that the top left value, 1, is in cell A1:

x=    1    2    3    4    5    6    7    8

      4    3    2    1    2    3    4    5

      9    8    7    6    7    8    9    10

      8    7    6    5    4    3    2    1

Sum= 21   18   15   12   13   14   15    16

There are x values from 1 to 8, and a three columns of values resulting from using it an equation or something below it. The sum is the sum of the three values below their corresponding x-value.

I'm stuck trying to figure something out that will go through the row of sums, find the smallest value, and then assign it's corresponding x-value to a variable. I also need to assign the values to the left and right of that x-value to other variables.

For this particular chart, 12 is the smallest of the sums, so I would assign variable1 = 4, since that is that column's corresponding x-value. Then my second variable, which is called lowerbound, would equal 3, since it is to the left of x = 4, and my third variable, which is called upperbound, would equal 5, since it is to the right of x = 4.

If I could get the cell address returned of the x-value that corresponds to the smallest sum, then I could assign it to a variable, and then simply offset from that cell to assign the other variables. Even if I could make a program that will return me the cell of the minimum sum value, I could offset to the x-row, and go from there.

How would I do something like that?

TL:DR: To ask more clearly, since that's a lot of words: What would a program look like that detects the smallest value in the sum row, and returns the cell address of that value?

The length of the rows are an unknown, and vary a lot, but the length of the columns are given. They do change depending on the problem, but they will always be known. So I will always know how many rows are in a column, but I will not know how many columns are in a row.

This is the most confusingly-worded thing I've ever written in my entire life, but I hope I've explained it well enough to make some sense.

You guys really are amazing, by the way. I've gotten so far on this program, and it's all because of how helpful you are. I honestly think I would still be stuck at the beginning with you guys! You're willing to tolerate a newbie's incessant questions.

like image 453
TheTreeMan Avatar asked Nov 30 '22 23:11

TheTreeMan


1 Answers

I am assuming that the sum is in A4:H4. Please change as applicable

You can use a formula like

=CELL("address",INDEX(A4:H4,MATCH(MIN(A4:H4),A4:H4,0)))

If you want to use VBA then you can use this

Sub Sample()
    MsgBox Application.Evaluate("=CELL(""address"",INDEX(A4:H4,MATCH(MIN(A4:H4),A4:H4,0)))")
End Sub
like image 83
Siddharth Rout Avatar answered Dec 03 '22 14:12

Siddharth Rout