Question : How do I create a looping to add values in columns?

I have a table with a list of company staff and another table with staff's sales figures:
TableA:
staff no      join date
0156          05/12/2009
0345          09/12/2009
1998          01/28/2010

Table B:
staff no       sales012009    sales 022009    ............    sales 052010
0156               388.88               990.00                             1045.91
0345               1235.21            2141.22                           9808.22

I need to calculate the TOTAL sales amount for EVERY staff in their first half year from their joining date, e.g. for 0156 who join at 05/12/2009, need to calculate his first half year Sales from 052009 to 102009 (sales052009+sales062009+sales072009+sales082009+sales092009+sales102009)

Can handle it either by Foxpro, Access or Excel.
Anybody pls help! Pls!!!!!!!!!!!!!!  Many thanks!

Answer : How do I create a looping to add values in columns?

Here's an example using Excel's Sumproduct formula, see attached file for result of formula:

=SUMPRODUCT((TableB!$B$1:$Y$1>=DATE(YEAR($B2),MONTH($B2),DAY(1)))*(TableB!$B$1:$Y$1<DATE(YEAR($B2),MONTH($B2)+6,DAY(1)))*(TableB!$B$2:$Y$4)*(TableB!$A$2:$A$4=$A2))

Random Solutions  
 
programming4us programming4us