close

A user posed this problem and I have no idea how to help him out. Any
suggestions or advice?

Thanks in advance for your help.

Jennifer Q

~~~~~~~
Suppose that I have a matrix that has say 13 rows and 6 columns. I wish to
write an EXCEL program that takes 5 rows at a time and computes the sum of
each column for the resulting matrix. The program is to record the maximum
of these column sums along with the rows for which the computation was made.
The program is to cycle through all 1287 possible combinations of five rows
repeating the column sum computations and recordings as indicated above.
An example matrix is shown below:
| A | B | C | D | E | F

1 | 1 2 1 1 4 8

2 | 5 8 7 4 1 5

3 | 9 6 2 9 9 6

4 | 6 5 5 7 7 7

5 | 11 13 6 3 3 2

6 | 8 7 11 2 5 10

7 | 3 12 4 10 8 4

8 | 4 1 8 12 12 11

9 | 12 3 10 8 10 1

10| 7 9 13 13 6 3

11| 10 10 12 11 2 13

12| 2 4 9 6 13 12

13| 13 11 3 5 11 9
Hi,

One possibility:

In G5 enter the formula and click ENTER,

=SUM(A1:A5)

Autofill the formula across H5, I5, J5, K5, and L5, and autofill the
formulas down to the last row (e.g., G13, H13, I13, J13, K13, and L13).
These formulas calculate the running 5-row sum for each column (A thru F)
cascading down through rows.

Now, to find the maximum of these sums for each column and also the
corresponding row numbers:

In G1, enter the following formula, and autofill across H1, I1, J1, K1, and
L1.

=MAX(G5:G13) ----gt; change the quot;13quot; to actual last row number.

In G2, enter the following formula, and autofill across H2, I2, J2, K2, and
L2.

=MATCH(MAX(G$5:G$13),G$5:G$13,0)amp;quot; - quot;amp;MATCH(MAX(G$5:G$13),G$5:G$13,0) 4
---gt; again, change the quot;13quot;s to actual last row number.

PS: Note that these formulas work only if the data start with Row 1. If
they don't, the formulas have to be modified slightly.Regards,
B. R. Ramachandran
quot;Jennifer Qquot; wrote:

gt; A user posed this problem and I have no idea how to help him out. Any
gt; suggestions or advice?
gt;
gt; Thanks in advance for your help.
gt;
gt; Jennifer Q
gt;
gt; ~~~~~~~
gt; Suppose that I have a matrix that has say 13 rows and 6 columns. I wish to
gt; write an EXCEL program that takes 5 rows at a time and computes the sum of
gt; each column for the resulting matrix. The program is to record the maximum
gt; of these column sums along with the rows for which the computation was made.
gt; The program is to cycle through all 1287 possible combinations of five rows
gt; repeating the column sum computations and recordings as indicated above.
gt;
gt;
gt;
gt; An example matrix is shown below:
gt;
gt;
gt;
gt; | A | B | C | D | E | F
gt;
gt; 1 | 1 2 1 1 4 8
gt;
gt; 2 | 5 8 7 4 1 5
gt;
gt; 3 | 9 6 2 9 9 6
gt;
gt; 4 | 6 5 5 7 7 7
gt;
gt; 5 | 11 13 6 3 3 2
gt;
gt; 6 | 8 7 11 2 5 10
gt;
gt; 7 | 3 12 4 10 8 4
gt;
gt; 8 | 4 1 8 12 12 11
gt;
gt; 9 | 12 3 10 8 10 1
gt;
gt; 10| 7 9 13 13 6 3
gt;
gt; 11| 10 10 12 11 2 13
gt;
gt; 12| 2 4 9 6 13 12
gt;
gt; 13| 13 11 3 5 11 9
gt;
gt;
gt;

Jennifer,
Here is another approach.
(add a quot;Maxquot; formula in a column to complete your request)
Jim Cone
San Francisco, USA
www.realezsites.com/bus/primitivesoftware

'-----------------
'Combinations sub by John Warren March 21, 2001
'Modified by Jim Cone April 06, 2006
'Calls Comb2 sub.
'Creates the list in a single column.
'Select the top cell of the column then run code.

Sub Combinations()
Dim n As Variant
Dim m As Variant
ReStart:
n = InputBox(quot;Number of items?quot;, quot;Combinationsquot;)
If Len(n) = 0 Then Exit Sub
m = InputBox(quot;Taken how many at a time?quot;, quot;Combinationsquot;)
If Len(m) = 0 Then GoTo ReStart

Application.ScreenUpdating = False
Comb2 n, m, 1, vbNullString, ActiveCell
Application.ScreenUpdating = True
End Sub'Comb2 sub by John Warren March 21, 2001
'Modified by Jim Cone April 06, 2006
'Generate combinations of integers k..n taken m at a time, recursively.

Sub Comb2(ByVal n As Integer, ByVal m As Integer, ByVal k As Integer, _
ByVal s As String, ByRef rng As Excel.Range)
If m gt; n - k 1 Then Exit Sub
If m = 0 Then
rng.Value = RTrim$(s)
Set rng = rng(2, 1)
Exit Sub
End If
Comb2 n, m - 1, k 1, s amp; k amp; quot; quot;, rng
Comb2 n, m, k 1, s, rng
End Sub

'--------------------------
'Jim Cone - San Francisco, USA - 04/06/2006
'User must select the single column of values created by
'the Combinations sub before running this code.
'Assumes the matrix is on quot;Sheet2quot; in A1:F13 and that the
'Number of Items is 13 and are taken 5 at a time.

Sub GetColumnMaxtrixTotals()
Dim rngCell As Excel.Range
Dim rngMatrix As Excel.Range
Dim arr As Variant
Dim lngR As Long
Dim lngC As Long
Dim lngSum As Double

Set rngMatrix = Worksheets(quot;Sheet2quot;).Range(quot;A1:F13quot;)

Application.ScreenUpdating = False
For Each rngCell In Selection.Cells
arr = Split(rngCell.Value, quot; quot;)
For lngC = 1 To 6
For lngR = 0 To 4
lngSum = lngSum rngMatrix(arr(lngR), lngC).Value
Next
rngCell.Offset(0, lngC).Value = lngSum
lngSum = 0
Next
Next
Application.ScreenUpdating = True
Set rngCell = Nothing
Set rngMatrix = Nothing
End Sub
'----------
quot;Jennifer Qquot; gt; wrote in message ...
A user posed this problem and I have no idea how to help him out. Any
suggestions or advice?
Thanks in advance for your help.
Jennifer Q

~~~~~~~
Suppose that I have a matrix that has say 13 rows and 6 columns. I wish to
write an EXCEL program that takes 5 rows at a time and computes the sum of
each column for the resulting matrix. The program is to record the maximum
of these column sums along with the rows for which the computation was made.
The program is to cycle through all 1287 possible combinations of five rows
repeating the column sum computations and recordings as indicated above.
An example matrix is shown below:
| A | B | C | D | E | F

1 | 1 2 1 1 4 8

2 | 5 8 7 4 1 5

3 | 9 6 2 9 9 6

4 | 6 5 5 7 7 7

5 | 11 13 6 3 3 2

6 | 8 7 11 2 5 10

7 | 3 12 4 10 8 4

8 | 4 1 8 12 12 11

9 | 12 3 10 8 10 1

10| 7 9 13 13 6 3

11| 10 10 12 11 2 13

12| 2 4 9 6 13 12

13| 13 11 3 5 11 9
Jennifer Q wrote...
gt;A user posed this problem and I have no idea how to help him out. Any
gt;suggestions or advice?

So you're getting paid to answer this, but you're asking for free help
doing so? Are you going to tell your user where you found an answer?

gt;~~~~~~~
gt;Suppose that I have a matrix that has say 13 rows and 6 columns. I wish to
gt;write an EXCEL program that takes 5 rows at a time and computes the sum of
gt;each column for the resulting matrix. The program is to record the maximum
gt;of these column sums along with the rows for which the computation was made.
gt;The program is to cycle through all 1287 possible combinations of five rows
gt;repeating the column sum computations and recordings as indicated above.
gt;
gt;An example matrix is shown below:
gt;
gt; 1 2 1 1 4 8
gt; 5 8 7 4 1 5
gt; 9 6 2 9 9 6
gt; 6 5 5 7 7 7
gt;11 13 6 3 3 2
gt; 8 7 11 2 5 10
gt; 3 12 4 10 8 4
gt; 4 1 8 12 12 11
gt;12 3 10 8 10 1
gt; 7 9 13 13 6 3
gt;10 10 12 11 2 13
gt; 2 4 9 6 13 12
gt;13 11 3 5 11 9

If you mean the user wants to keep track of the max column sum in each
column separately, it's trivial. Given the array above in A1:F13, the
max sum in col A would be

=SUM(LARGE(A1:A13,{1;2;3;4;5}))

and the rows involved would be given by

=MATCH(LARGE(A1:A13,n),A1:A13,0)

where n = 1..5.

On the other hand, if the user is keeping track of all the column sums
together, then they'd need to be combined into an ordinal metric which
you haven't specified.WOW! Thanks for all the helpful suggestions. I'll share these with him and
see if they work for him.

Harlan,
I get paid to make sure his computer keeps working, not to come up with the
answers to squirrely problems like these. Of course I will tell him where
the answers came from. I would never take credit for something I don't quite
understand.

Thanks again, everybody, for your help!

Jenniferquot;Jennifer Qquot; gt; wrote in message
...
gt;A user posed this problem and I have no idea how to help him out. Any
gt;suggestions or advice?
gt;
gt; Thanks in advance for your help.
gt;
gt; Jennifer Q
gt;
gt; ~~~~~~~
gt; Suppose that I have a matrix that has say 13 rows and 6 columns. I wish
gt; to write an EXCEL program that takes 5 rows at a time and computes the sum
gt; of each column for the resulting matrix. The program is to record the
gt; maximum of these column sums along with the rows for which the computation
gt; was made. The program is to cycle through all 1287 possible combinations
gt; of five rows repeating the column sum computations and recordings as
gt; indicated above.
gt;
gt;
gt;
gt; An example matrix is shown below:
gt;
gt;
gt;
gt; | A | B | C | D | E | F
gt;
gt; 1 | 1 2 1 1 4 8
gt;
gt; 2 | 5 8 7 4 1 5
gt;
gt; 3 | 9 6 2 9 9 6
gt;
gt; 4 | 6 5 5 7 7 7
gt;
gt; 5 | 11 13 6 3 3 2
gt;
gt; 6 | 8 7 11 2 5 10
gt;
gt; 7 | 3 12 4 10 8 4
gt;
gt; 8 | 4 1 8 12 12 11
gt;
gt; 9 | 12 3 10 8 10 1
gt;
gt; 10| 7 9 13 13 6 3
gt;
gt; 11| 10 10 12 11 2 13
gt;
gt; 12| 2 4 9 6 13 12
gt;
gt; 13| 13 11 3 5 11 9
gt;
gt;
Thanks for your idea, but this does not give us all 1287 combinations.quot;B. R.Ramachandranquot; gt; wrote in
message ...
gt; Hi,
gt;
gt; One possibility:
gt;
gt; In G5 enter the formula and click ENTER,
gt;
gt; =SUM(A1:A5)
gt;
gt; Autofill the formula across H5, I5, J5, K5, and L5, and autofill the
gt; formulas down to the last row (e.g., G13, H13, I13, J13, K13, and L13).
gt; These formulas calculate the running 5-row sum for each column (A thru F)
gt; cascading down through rows.
gt;
gt; Now, to find the maximum of these sums for each column and also the
gt; corresponding row numbers:
gt;
gt; In G1, enter the following formula, and autofill across H1, I1, J1, K1,
gt; and
gt; L1.
gt;
gt; =MAX(G5:G13) ----gt; change the quot;13quot; to actual last row number.
gt;
gt; In G2, enter the following formula, and autofill across H2, I2, J2, K2,
gt; and
gt; L2.
gt;
gt; =MATCH(MAX(G$5:G$13),G$5:G$13,0)amp;quot; - quot;amp;MATCH(MAX(G$5:G$13),G$5:G$13,0) 4
gt; ---gt; again, change the quot;13quot;s to actual last row number.
gt;
gt; PS: Note that these formulas work only if the data start with Row 1. If
gt; they don't, the formulas have to be modified slightly.
gt;
gt;
gt; Regards,
gt; B. R. Ramachandran
gt;
gt;
gt;
gt;
gt;
gt;
gt;
gt;
gt;
gt; quot;Jennifer Qquot; wrote:
gt;
gt;gt; A user posed this problem and I have no idea how to help him out. Any
gt;gt; suggestions or advice?
gt;gt;
gt;gt; Thanks in advance for your help.
gt;gt;
gt;gt; Jennifer Q
gt;gt;
gt;gt; ~~~~~~~
gt;gt; Suppose that I have a matrix that has say 13 rows and 6 columns. I wish
gt;gt; to
gt;gt; write an EXCEL program that takes 5 rows at a time and computes the sum
gt;gt; of
gt;gt; each column for the resulting matrix. The program is to record the
gt;gt; maximum
gt;gt; of these column sums along with the rows for which the computation was
gt;gt; made.
gt;gt; The program is to cycle through all 1287 possible combinations of five
gt;gt; rows
gt;gt; repeating the column sum computations and recordings as indicated above.
gt;gt;
gt;gt;
gt;gt;
gt;gt; An example matrix is shown below:
gt;gt;
gt;gt;
gt;gt;
gt;gt; | A | B | C | D | E | F
gt;gt;
gt;gt; 1 | 1 2 1 1 4 8
gt;gt;
gt;gt; 2 | 5 8 7 4 1 5
gt;gt;
gt;gt; 3 | 9 6 2 9 9 6
gt;gt;
gt;gt; 4 | 6 5 5 7 7 7
gt;gt;
gt;gt; 5 | 11 13 6 3 3 2
gt;gt;
gt;gt; 6 | 8 7 11 2 5 10
gt;gt;
gt;gt; 7 | 3 12 4 10 8 4
gt;gt;
gt;gt; 8 | 4 1 8 12 12 11
gt;gt;
gt;gt; 9 | 12 3 10 8 10 1
gt;gt;
gt;gt; 10| 7 9 13 13 6 3
gt;gt;
gt;gt; 11| 10 10 12 11 2 13
gt;gt;
gt;gt; 12| 2 4 9 6 13 12
gt;gt;
gt;gt; 13| 13 11 3 5 11 9
gt;gt;
gt;gt;
gt;gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()