I'm currently facing a problem in Excel. I'm trying to make a list, where I can track how often each employee is out of office (put in manually, for each day).
This is not a big issue, I managed to do that with this formula:
=SUMPRODUCT(COUNTIF($F$8:$AJ$8;$B$19:$B$21&""))
The Problem I'm facing is, that I have a fixed range 31(days). If a month only has 30 days/28 days, it will show 1(3) days of the next month. Because of that, percentage calculations are messed up.
Is there a way to change the range of the formula, if a month has less than 31 days?
Is there a way to change the formula, to ignore the days of the next month?
I would use a formula like so
=SUM(OFFSET($B$1,MATCH(G8,$A$1:$A$19,0)-1,(EOMONTH(TODAY(),-1)-DATE(2017,1,1))+1,1,DAY(EOMONTH(TODAY(),0)))) based on your example
Something like this for the data
Related
Here's a simplification of my data. I have these events occurring by date. The "x" marks the day each event occurred.
What I'm doing is counting how many events happened in each month, using COUNTIF(). So I have something like:
The problem is: I use one COUNTIF() for each month and it can be very tricky when you have, let's say, 50 months.
How can I resolve this with VBA? If wasn't separated by date would be easy, but I haven't able to solve this.
I appreciate it if someone can help.
Just use a Pivot Table to group by month-end and count the records.
https://trumpexcel.com/group-dates-in-pivot-tables-excel/
https://www.myexcelonline.com/blog/group-month-excel-pivot-tables/
If you need to do this frequently, you can record a Macro, save it, and run it whenever you need it.
I have an excel document with a main sheet and 1 sheet for every day of the month.
Every month this excel document will be filled with data for each day.
The main sheet has to show the average and sum of the data of each weekday.
My problem is that every month the weekdays are on other days in the month, so I can't simply use the 1st day of the month for a monday.
I start with an empty Excel document with only the main sheet.
My VB6 program then adds the sheet for each monthday with the data.
I know how to fill the monthday sheets with data, but I don't know how to fill the cells in the main sheet with a formula.
The average and sum formula's in the main sheet have to be dynamic to chose which sheets are mondays, tuesday, etc.
Here are some simplified examples of the sheets of january and february:
The real monthday sheets contain much more data, and the main sheet more analyses. See below for a part of it:
I see various way to go for solving this:
from my VB6 program
via VBA in the excel document
via a more complex excel formula
having the main sheet in a separate document, while filling another excel document with the monthday data which can be accessed from the main sheet.
How can I make sure the cells in the main sheet always use the right weekday, or how can I from my VB6 program write a formula in the cells in the main sheet?
First, if you can, I suggest you change your workbook structure to use a tidy data layout, i.e. don't have separate sheets for each day but rather concatenate all your data and add a column for day of month. Then you can just use a single pivot table.
Failing that, make a column of numbers 1 to 31, make a cell with the year and another with the month. Use =DATE() to make a cell of the dates for the month and then use =WEEKDAY() to get the week day for each month. In another column average and sum your data per day of month. then either use a pivot table or just SUMIF to aggregate this up to a day of week level.
I required output like this. I have planned hours for each month and want to split planned hours between two resources from their start date and end date. Example: For manager role planned hours for june month are 80. Resource 1 is working from 1-Apr to 15-Jun and resource 2 is working from 16-Jun to 30-Sept then formula or code should split june hours between this two resources. Like I shown below
Any thoughts? I don't mind if it's an Excel formula or a vba code
using below formula I am getting output for engineer role but not for manager role.
=IF(AND($D4<=F$3,$E4>=EOMONTH(F$3,0)),80,0)
I wonder if this formula will work for you.
=ROUND((MAX(F$12-MAX($C13,E$12),0)-MAX(F$12-MAX($D13,E$12),0))*E$11/30,-1)
In this example, columns C and D hold the resources' start and end dates.
E12 holds the date of Apr 1, 2017, F12 the formula =EDATE(E12,1) copied to the right as far as required. You can format these dates to show just month and year as per your form but the formula expects them to be the first day of each month.
E$11 holds the value of 80 (hours) in your example.
Its a little convoluted and formula maintenance will be a pain in the arse, but the formula below pasted into F2 and copied down and right seems to work:
=IF(OR(EOMONTH(F$3,0)<EOMONTH($D4,0),EOMONTH(F$3,0)>EOMONTH($E4,0)),0,
IF(IF(EOMONTH($D4,0)=EOMONTH($E4,0),$E4-$D4,IF(EOMONTH($D4,0)=EOMONTH(F$3,0),EOMONTH(F$3,0)-$D4+1,IF(EOMONTH($E4,0)=EOMONTH(F$3,0),$E4-F$3+1,DAY(EOMONTH(F$3,0)))))<=7,1,
IF(IF(EOMONTH($D4,0)=EOMONTH($E4,0),$E4-$D4,IF(EOMONTH($D4,0)=EOMONTH(F$3,0),EOMONTH(F$3,0)-$D4+1,IF(EOMONTH($E4,0)=EOMONTH(F$3,0),$E4-F$3+1,DAY(EOMONTH(F$3,0)))))<=15,2,
IF(IF(EOMONTH($D4,0)=EOMONTH($E4,0),$E4-$D4,IF(EOMONTH($D4,0)=EOMONTH(F$3,0),EOMONTH(F$3,0)-$D4+1,IF(EOMONTH($E4,0)=EOMONTH(F$3,0),$E4-F$3+1,DAY(EOMONTH(F$3,0)))))<=23,3,4))))/4*F$2
I would work nicer with some intermediate cell calculations in order to avoid the repeated nested if statements. I am sure it can be simplified.
I am using a SUMIFS formula in Excel to calculate different expenses throughout the months of the year. I am trying to build a permanent solution where I only have to update the year in a different cell, and it will carry through the SUMIFS formulas used throughout the page.
Every approach I have taken has voided the formula. Here is what I have:
'=SUMIFS(D:D,B:B,">=1/1/2015",B:B,"<=1/31/2015",E:E,"XYZ")
Try
=SUMIFS(D:D,B:B,">="&DATE(A2,1,1),B:B,"<="&DATE(A2,12,31),E:E,"XYZ")
A2 in this case is the location of the year.
Note: It would seem #ScottCraner and I had the same solution.
Okay, so here is a sample my current code. I have this in several cells , where B-H7 reflect the absence type it is searching for.
=COUNTIFS('Old Data'!$A:$A,Tracking!A8,'Old Data'!$B:$B,$E$7, 'Old Data'!D:D, ">"&$B$5, 'Old Data'!D:D, "<"&$C$5)
What this code is doing is looping through a spreadsheet, where the employee name is found in the data sheet, comparing the absence types and assorting them to their respective columns and counting them, the last bit of code restricts the search between date ranges.
That being said, I need to add conditions to this that I'm not sure I can without taking it into VBA. In the "Old Data" Sheet in column D I have start time, which displays in MM/DD/YY HH:MM format. In Column E I have End Time, which displays in the same MM/DD/YY HH:MM format.
I need to have a way to
A.) Have the progam count the number of days between these dates and a +1 to the count for each respective day.
B.) If the start and end date are the same, have the program compare the number hours. if it is less than 4, only add a .5 to the counter.
My first thought is to scratch the countifs formula and loop through and parse it out using VBA, but I thought I'd check first to see if it can be done with just the formula as the power of the built in function has been pretty surprising to me so far.
I think I should probably take this from a formula to a VBA function and call it in the cells, but I'm not entirely sure, pretty new to the VBA/Excel scene.
Also, I'm in Excel 2007.
Thanks for any input on this issue!
It's possible to do with a formula but not with COUNTIFS. This array formula should do it
=SUM(IF(('Old Data'!$A$2:$A$100=Tracking!A8)*('Old Data'!$B$2:$B$100=$E$7)*('Old Data'!$D$2:$D$100>$B$5)*('Old Data'!$D$2:$D$100<$C$5),IF('Old Data'!$E$2:$E$100-'Old Data'!$D$2:$D$100<"4:00"+0,0.5,INT('Old Data'!$E$2:$E$100)-INT('Old Data'!$D$2:$D$100)+1)))
confirmed with CTRL+SHIFT+ENTER
I restricted the data range to rows 2 to 100, adjust as required, whole columns is possible but that may slow down the formula considerably
To count workdays only change to this version:
=SUM(IF(('Old Data'!$A$2:$A$100=Tracking!A8)*('Old Data'!$B$2:$B$100=$E$7)*('Old Data'!$D$2:$D$100>$B$5)*('Old Data'!$D$2:$D$100<$C$5),IF('Old Data'!$E$2:$E$100-'Old Data'!$D$2:$D$100<"4:00"+0,0.5,NETWORKDAYS('Old Data'!$D$2:$D$100+0,'Old Data'!$E$2:$E$100+0))))
You can also exclude holidays if you add a holiday range to the NETWORKDAYS function