English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have two excel columns (A and B) with different numbers (each column has 135 numbers). Two sums (SUM(A1:A135) and SUM(B1:B135)) of each column are different. I need to find the minimum sum of the combinations from two columns. The combination includes numbers with every indices from 1 to 135 and numbers with only one index, for example, if it includes A3, then it exclude B3. There is condition that the sum of chosen numbers from B column has to be more than or equal to that of A column.

2006-11-28 23:11:31 · 4 answers · asked by Bilguun 2 in Computers & Internet Programming & Design

4 answers

I'm not sure if I have clearly understood the question, but if what I understand is correct, you have some complicated math on your hands.

I would use an Excel macro to handle this. This is assuming a somewhat random mix of numbers in rows 1..135.

Here's an example: (just off the top of my head, so I don't know if this would work)

Sub FindMinimumSum ()

sumA=0
sumB=0
for i=1 to 135
a= worksheets("Sheet1").cells(i,"A").value
b= worksheets("Sheet1").cells(i,"B").value
if a>=b then sumB=sumB+B else sumA=sumA+A
next i
TOTALSUM=sumA +sumB

'These next three lines will WRITE data to your spreadsheet!!!
worksheets("Sheet1").cells(1,"C").value=SumA
worksheets("Sheet1").cells(2,"C").value=SumB
worksheets("Sheet1").cells(3,"C").value=TOTALSUM

End Sub

Just copy and paste that macro into your Excel Visual Basic code, and then run it. NOTE: If you have data in Column "C", rows 1,2, & 3, then you will want to change the last three lines to put the numbers where you want them (in empty cells somewhere). You might also like to backup your file--Once a macro is run, Excel will not UNDO it!

2006-11-29 00:39:02 · answer #1 · answered by AsiaWired 4 · 0 0

Why not add a third column C with the function:

=if(A1 .
.
.
=if(A135

and then sum that column?

2006-11-30 10:41:50 · answer #2 · answered by nospamcwt 5 · 0 0

Have you tried copy - paste { values / transpose } ? It normally works unless you are selecting a range of different size to paste the output. Alternatively, you can create a macro that reads values one by one and pastes them out in a column.

2016-05-23 01:32:07 · answer #3 · answered by ? 4 · 0 0

use SumIF()
it allows you to set conditions on whether or not to include a number in a range.
there is help available in excel for this function, but if you use the function tool - it steps you through anyway

2006-11-28 23:14:33 · answer #4 · answered by Ruthie Baby 6 · 0 0

fedest.com, questions and answers