I am just wondering if there is a way that I can convert the contents of the column described in the picture I have attached to a total of running seconds where the first row is of course zero seconds so that the next row would be ~8220 seconds and so on. This would make the analysis of time-series data much easier for me.
Picture
Tl; dr: How can I use VBA to autofilter dates based on dates entered in two cells (one for start date and one for end date)?
I'm trying to autofilter with VBA in Excel. I have a dataset that contains multiple rows (that change in the amount of rows every day). Seeing how I can have a macro that would automatically delete out dates that are outside of a range that the user would enter in two cells (one for the beginning of the date range and one for the end of the date range). I have code that pulls the data from its source and formats it, but the code to delete out the rows that fall outside of the date range I don't have any at this time. The dates could constantly change, some are before the start date and some are after the end date.
For example, if a user enters a start date of 2/1/2019 and an end date of 3/1/2019, then the autofilter would delete any before 2/1 and any after 3/1. The following week may have a completely different start and end date, so it would need to come from the cells rather than the dates themselves entered in the code.
The goal is to eventually have a count of the number of dates that appear in this dataset within the date range given, so alternatively the data could remain unchanged and just have a count of those dates. However I'd like to avoid this as it will eventually go in a report and I don't want to confuse the readers of the report if it contains older dates/dates after the date range.
I mentioned in the first paragraph that the data may change. This is because the rows above the dataset may be deleted or have some added. I haven't tested this out but a solution I've seen is here, where the range would always be referenced correctly. https://www.thespreadsheetguru.com/blog/5-ways-to-create-a-dynamic-auto-adjusting-vba-range
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'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
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