I have the following situation:
I have a work sheet which contains a list of work with the estimated hours.
These hours can be assigned to users (listed in column D and E) using column C.
Now I want calculate the assigned hours per user in columns D E and F.
I am able to fill in the values for the not calculated fields using the following function:
I am using already the following functions (removed the $ sign for readability and I am using record 3 as example because it is not calculated)
- Calculation for assigned hours :
=IF(C3=D1;B3;0). So if the name of the user is equal to the name of the assigned user then the value will be used, otherwise 0. - Calculation for not assigned hours :
=SUM(D3:E3) - B3. So if the assigned user does not exist in the columns then the hours are not assigned.- EDIT I have edited the calculation for not assigned hours. The previous version was:
=IF(AND(C3<>D1; C3<>E1);B3;0)
- EDIT I have edited the calculation for not assigned hours. The previous version was:
These two calculations works fine but of course not for the calculated fields.
What I want to accomplish
Now I want to fill in the calculations on the question marks. This is easy if you know where the calculated fields are placed but that can be everywhere. So I need to have a function which does the following thing:
if: The value of columns B is calculated
then: calculate all values for the certain user until the next calculated row
else: use one of the two calculations I have already described
Requested results using the sample sheet:
?1?:SUM(D3;D6)?2?:SUM(E3;E6)?3?:SUM(F3;F6)?4?:SUM(D8;D9)?5?:SUM(E8;E9)?6?:SUM(F8;F9)
Example sheet
A B C D E F
1| Tasks | Hours |Assigned To| User1 | User2 |Not Assigned|
2|Main Task |=SUM(A3:A6)| | ?1? | ?2? | ?3? |
3| Sub Task | 10 | User1 | 10 | | |
4| Sub Task | 25 | User2 | | 25 | |
5| Sub Task | 14 | User2 | | 14 | |
6| Sub Task | 17 | User1 | 17 | | |
7|Main Task |=SUM(A8:A9)| | ?4? | ?5? | ?6? |
8| Sub Task | 22 | User2 | | 22 | |
9| Sub Task | 43 | | | | 43 |
Explanation:
Column A: Each sub task has one extra indent (using the
button) in comparison with its parent task.
Column B: The value in this column will be calculated if the item contains subitems
Task 1 Calculated because contains subtasks (Task 1.1 and Task 1.2)
Task 1.1 Calculated because contains subtasks (Task 1.1.1 and Task 1.1.2)
Task 1.1.1 Not calculated because no subtasks
Task 1.1.2 Not calculated because no subtasks
Task 1.2 Not calculated because no subtasks
Task 2 Not calculated because no subtasks
Task 3 Calculated because contains subtasks (Task 3.1)
Task 3.1 Not calculated because no subtasks
Column C: Only not calculated columns can be assigned to a user
Column D - E: The header contains the name of the user where tasks can be assigned to
Column F: Contains the not assigned hours per task
You can determine which cells have formulas like so:
[Edit for VBA]
You can create a User Defined Function like the one at Does Cell Have Formula from Excel VBA then use it like: