excel vba shifting formulas based on sales lead time - excel

I trying to find the correct code to move my formulas over x number of cells. The x would represent sales lead time. Lets say I make a January sale, but that revenue wont actually be received until 7 months later. So for Jan I wont receive until July, for Feb I wont receive until August, for March I wont receive until September and so on.
I'm looking for something to automate or shift my formulas that total my sales over based on a lead time cell. So lets say I change my lead time to 5 months everything shifts over to reflect 5 months instead of 7.
Any help would be greatly appreciated.
Hope thats not too confusing.
Thanks for any help!

You seem to be looking at the problem from the wrong end: Instead of asking when your January sales proceeds will be received, try asking which proceeds you will receive in July. Then you arrive at a structure like this:-
Column A = Date of sale
Column B = Description
Column C = Sales amount
Column D = Expected delay in months
Column E and up = Jan, Feb, etc. one column for each month
Write the starting date in cell E1, say 1/1/2017.
In F1 paste this formula: =DATE(YEAR(E1),MONTH(E1)+1,1)
Format the range E1:F1 as 'Custom' using the string MMM yy
Copy F1 to the right as far into the future as you require
Now you have a column for each month. If you change the value in E1 all captions will change accordingly. That's good when you need a new sheet for next year.
Write this formula in E2: =IF(MONTH($A2) + $D2 = MONTH(E$1), $C2,0)
Copy right and down as far as you require
Now, make an entry. Say on Jan 17 you had a sale of $1200 and you expect to receive the money 6 months later.
Enter the date in column A = 17/1/2017
Enter the amount in column C = 1200
Enter the expected delay in column D = 6
The amount appears in the July column. Change the value in column D to 3 and the amount moves to April.
All the other columns show a zero. If you don't like that, go to File ->Options -> Advanced >>Display options for this worksheet = uncheck the checkbox for "Show a zero in cells that have zero value".

Related

RE: Excel formula for staff training

=IF(OR(AND(E4="Active",G4<TODAY()),ISBLANK(G4)), "Overdue", "OK")
That is my current formula. G4 = date they last completed training, E4 = column stating whether they are active or not - if not then I don't want it to display Overdue. If G column is blank & E column is active I want it to display Overdue.
The problem:
I have got a database of staff names, and then whether they are active, and then if they are due training. I need a formula that takes into account if they are active or not, then if the date their training is Overdue (if the date is 1 year + past the completion date of their last training) and to display this in a new column as Overdue or OK. Ok being they don't need to book training. Additionally if the G column is blank it should treat that as over a year since the last training.
So only if the staff are "active" should it display Overdue in the final column. (as well as the date of G column being over a year before the current days date).
Im struggling to get my above formula to work :/ any assistance would be much appreciated
Ignoring leap years (for simplicity), maybe:
=IF(AND(E4="Active",G4<TODAY()-365), "Overdue", "OK")

In Excel how to count between date1 and date2 that have cells in row that contain text?

I need to choose cells in one column that are between two dates, and then based on the rows that contain those dates, choose cells in another row that also contains content.
I didn't use ISBLANK because it counts a formula yet an empty cell as a not-blank. Instead check if there is content by "*".
Here is what I came up with, but instead of returning the number of cells, instead this returns TRUE (which obviously isn't what I want).
In the formula below I am assuming:
C:C is the whole column containing DATES.
E:E is the whole column containing CONTENT.
The date range in this case is January 1, 2018 to January 31, 2018.
"*" means is there is content in the cell
=IF(AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*"))=0,"",AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*")))
My goal is to:
count the numbers of the cells in column E that are between the dates in column C
if the whole formula is 0, then return a blank.
See this picture of a sample excel sheet to make my intent clear:
How can I get my formula working so it does as needed?
SOLUTION
Hi all, so thanks to #girlvsdata, we have a working solution. I had to do a couple edits to her code to work for my uses, but her formula overall works perfect. Here is the solution:
To choose all cells in column E that are not blank, in between the date range of all of January (unknown end date) based on the adjacent C column if that is your date column, then the solution is:
=IF(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*")=0,"",COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*"))
Note that "2018-1-1" is January 1 2018, and EOMONTH("2018-1-1",0) is the last valid day of January in the year 2018 (in this case, 31, but if it is different another year (e.g. for February this works for leap years too) then it will be that last day). Also it eliminates the need to calculate which is the last day or every month, as well as months that have changing end dates dependent on the year (e.g. Feb). This is important to eliminate a margin of error.
The only thing you have to do to change the month is only change e.g. -1- (Jan) to -2- for Feb, or change the year for other years. With this formula you can ignore the day part.
If the answer is 0 (no cells have any content in between the range), then the cell is blank instead of 0. (GOod for when you want to create a sheet checking future dates for future reference when more rows are added to the sheet.
It also works across different sheets, just use, say your other sheet is called "Tracker" then use Tracker!C:C and Tracker!E:E. Hope it helps!
Thank you all! :D
(Please note: My local date format is day, then month)
With the data laid out as in your example above:
A B
1 Dates |Content
------------+-------
2 1/01/2018 |
3 2/01/2018 |123456
4 3/01/2018 |
5 4/01/2018 |12398
6 5/01/2018 |484
7 6/01/2018 |1538
8 7/01/2018 |
9 8/01/2018 |
10 9/01/2018 |
11 10/01/2018 |14648
12 11/01/2018 |
13 12/01/2018 |145615
14 13/01/2018 |
And with the date range in cells D2 and E2:
Date Start Date End
2/01/2018 7/01/2018
This formula returns the count:
=COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")
This will depend on whether your numbers in Column B are formatted as text or number. If they are formatted as numbers, the above formula will work. If they are formatted as text, replace the last section ">0" with "*".
This formula adds the conditional part of your question:
=IF(COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")=0,"",COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0"))
(If the formula returns 0, show blank)

Excel function to calculate pairwise date difference

I have a excel sheet with all employees of my company. This list also includes the sick days of each employee. I want to calculate the sick days of each year.
My excel sheet looks like this (shortened version):
A B C D E F G ...
1 Name From To From To From To ...
2 Max 2015/06/15 2015/06/16 2016/08/17 2016/08/17
3 Sarah 2016/01/20 2016/01/20
4 Phil
...
Explanation: Max was sick for two times. First from 2015/06/15 to 2015/06/16 and second from 2016/08/17 to 2016/08/17. Every time he gets sick the table is expanded to the right. Sarah was sick only on 2016/01/20 and Phil wasn't sick.
Now, I want to calculate the sick days of a year.
I could do something like
A B
10 2015 Sum of sick days in 2015
11 2016 Sum of sick days in 2016
So what needs to be done is:
check if date is in the right year
pairwise calculation of networkdays of all dates in a row, that means
=SUM(NETWORKDAYS(B2;C2)) for 2015 and
=SUM(NETWORKDAYS(D2;E2);NETWORKDAYS(B3;C3)) for 2016.
But it should work more dynamically. I only want to choose the matrix, e.g. A1 to I8 for each year and the rest should be calculated automatically. Does anybody know how I can do that?
You can use the below formula. (paste this in the cell B10
=SUMPRODUCT((YEAR($B$2:$N$8)=$A10)*(MOD(COLUMN($B$2:$N$8),2)=0)*(($C$2:$O$8-$B$2:$N$8)+1))
Copy the above cell into B11. It should work.
The following seems quite unruly:
=IF(YEAR(C2)=A10,NETWORKDAYS(B2,C2))+IF(YEAR(G2)=A10,NETWORKDAYS(F2,G2))+IF(YEAR(K2)=A10,NETWORKDAYS(J2,K2))+IF(YEAR(C3)=A10,NETWORKDAYS(B3,C3))+IF(YEAR(G3)=A10,NETWORKDAYS(F3,G3))+IF(YEAR(K3)=A10,NETWORKDAYS(J3,K3))+IF(YEAR(C4)=A10,NETWORKDAYS(B4,C4))+IF(YEAR(G4)=A10,NETWORKDAYS(F4,G4))+IF(YEAR(K4)=A10,NETWORKDAYS(J4,K4))
Alternatively you could either write a macro to loop through the data or add an additional two columns in between each From and To column. D2 would be
=IF(ISBLANK(C2),"",YEAR(C2))
and copy down. E2 would be
=IF(ISBLANK(C2),"",NETWORKDAYS(B2,C2))
and copy down. E11 would be
=SUMIF(D2:D4,$A11,E2:E4)
and copy across to I11 and M11 etc. You can then just
=SUM(C11:M11)
These new columns can be hidden if you needed.

SUM values based on date in date range in array

i'm realy newbie in excel and i need to make advanced functions
I have excel (from Google Calendar) with booking system
A B C
12-01-2012 14-01-2012 8
13-01-2012 17-01-2012 11
15-01-2012 21-01-2012 3
A - start date
B - end date
C - number of guests
Now I need to SUM number of guest for all days in year and find every days where was more than 10 reservations.
For example, I need to return
12-01-2012 - 08 guests
13-01-2012 - 19 guests
14-01-2012 - 19 guests
15-01-2012 - 14 guests
May I do it without creating large excel file with all days combinations? And how?
I'm working on excel 2013.
This can be done quite simply by using the SUMIFS function. First you need to put each date in column D (set the first date you care about manually, then in D2 below, just say =D1+1 and copy down). Then to count the people for each of those days, put this in E1 and drag down:
=SUMIFS(C:C, A:A, ">="&D1, B:B,"<="&D1)
This will Sum the passengers listed in column C (must be formatted as numbers, not text - it looks like you might have some text values in there), if that row in column D (each day in the year) is within the range of Column A & Column B.
To find days larger than 10 people, simply have column F (in F1 and dragged down) say
=E1>=10
This will say TRUE if column E shows more than 10 people for that day.

Sum values in a column based on date

I have written this function that will give me a monthly sum for two columns: one has the date of each order, one has the cost of each order.
=SUMIF($C$1:$C$1000,">="&DATE(2010,6,1),$D$1:$D$1000)-SUMIF($C$1:$C$1000,">="&DATE(2010,7,1),$D$1:$D$1000)
Using data like this:
8/16/10 17:00 7.99
8/16/10 14:25 7.99
8/15/10 22:42 7.99
I end up with a table like this:
May 998
June 968.28
July 1239.76
August 514.96
However, now I would like to do daily sums and using my way I have to hand edit each row.
How can I do this better in Excel?
Use a column to let each date be shown as month number; another column for day number:
A B C D
----- ----- ----------- --------
1 8 6 8/6/2010 12.70
2 8 7 8/7/2010 10.50
3 8 7 8/7/2010 7.10
4 8 9 8/9/2010 10.50
5 8 10 8/10/2010 15.00
The formula for A1 is =Month(C1)
The formula for B1 is =Day(C1)
For Month sums, put the month number next to each month:
E F G
----- ----- -------------
1 7 July $1,000,010
2 8 Aug $1,200,300
The formula for G1 is =SumIf($A$1:$A$100, E1, $D$1:$D$100). This is a portable formula; just copy it down.
Total for the day will be be a bit more complicated, but you can probably see how to do it.
Use pivot tables, it will definitely save you time. If you are using excel 2007+ use tables (structured references) to keep your table dynamic. However if you insist on using functions, go with Smandoli's suggestion. Again, if you are on 2007+ use SUMIFS, it's faster compared to SUMIF.
Following up on Niketya's answer, there's a good explanation of Pivot Tables here:
http://peltiertech.com/WordPress/grouping-by-date-in-a-pivot-table/
For Excel 2007 you'd create the Pivot Table, make your Date column a Row Label, your Amount column a value. You'd then right click on one of the row labels (ie a date), right click and select Group. You'd then get the option to group by day, month, etc.
Personally that's the way I'd go.
If you prefer formulae, Smandoli's answer would get you most of the way there. To be able to use Sumif by day, you'd add a column with a formula like:
=DATE(YEAR(C1), MONTH(C1), DAY(C1))
where column C contains your datetimes.
You can then use this in your sumif.
Add a column to your existing data to get rid of the hour:minute:second time stamp on each row:
=DATE(YEAR(A1), MONTH(A1), DAY(A1))
Extend this down the length of your data. Even easier: quit collecting the hh:mm:ss data if you don't need it. Assuming your date/time was in column A, and your value was in column B, you'd put the above formula in column C, and auto-extend it for all your data.
Now, in another column (let's say E), create a series of dates corresponding to each day of the specific month you're interested in. Just type the first date, (for example, 10/7/2016 in E1), and auto-extend. Then, in the cell next to the first date, F1, enter:
=SUMIF(C:C, E1, B:B )
autoextend the formula to cover every date in the month, and you're done. Begin at 1/1/2016, and auto-extend for the whole year if you like.
If the second row has the same pattern as the first row, you just need edit first row manually, then you position your mouse pointer to the bottom-right corner, in the mean time, press ctrl key to drag the cell down. the pattern should be copied automatically.

Resources