Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

APPROACH:

I have the following Excel sheet called “Daily Planning” for daily planning of tasks for some projects:

http://es.tinypic.com/view.php?pic=i4pp4w&s=8#.U945LWMs8tE

(I can not upload images yet)


And I have another sheet called “Planning Overview” to see the hours per week and project:

http://i57.tinypic.com/iw2ih0.jpg


This second sheet takes data from “Daily Planning” and, for each cell, sums the hours that match with corresponding project and week.

As I haven’t found any native Excel formula to conditionally sum the values in an array, based on a corresponding row and column of reference, I created the following function:

Function VALUESBYWEEKS(matrix, weeksrow, week, projectcolumn, project)

Dim row As Long
Dim col As Long
row = matrix.Rows.Count
col = matrix.Columns.Count

'For each row'
   For i = 1 To row

'Analyze each column, in order to'
    For j = 1 To col

'Analyze each cell of the matrix, if cell is not empty (to reduce runtime)'
    If Not IsEmpty(matrix (i, j) ) Then

        'Now evaluate if the corresponding weeks cell is equal to the desired week'            
             If weeksrow (1, j) = week Then

             'And if the corresponding project cell is equal to the desired project'            
                 If projectcolumn (i, 1) = project Then

                 'Sum the value of the target cell to the total'
                     VALUESBYWEEKS = VALUESBYWEEKS+ matrix (i, j)

                 End If

             End If

     End If

   Next j

 Next i

End Function

Application example:

es.tinypic.com/r/2uqnfrk/8


THE ISSUE:

All this works fine on a small scale, but in the actual model, the matrix have about 700,000 cells. Although most of the cells are empty, the computing time is very high (about 3 seconds by every cell in “Planning Overview”, multiplied by 644 cells, makes a total of 30 minutes, and Excel recalculates all values at every change…)

I tried to optimize the formula to take into account only the empty cells but I think this doesn’t work.


So here are my questions:

  1. Is there any Excel formula (or combination of formulas) that I have ignored to achieve my goal?

  2. If not, do you know an specific way to approach the code in order to significantly reduce the execution time?


Thanks for your consideration and sorry for my English ; )

share|improve this question
    
I am sure you will be able to accomplish the same using SUMPRODUCT.. have you tried it? Try this link office.microsoft.com/en-in/excel-help/… –  YVXS yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.