How to do a row-wise COUNTIF, grouping by date - vba

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.

Related

Compare Dates in a column corresponding to Changes in an other row

I have a large sample of medical data I need to try and analyze patterns in Excel worksheet.
I also put them up in a database in MS ACCESS to do my first filters and stuff.
I have the infos of patients, with tests results(POS or NEG), dates of the sample.
I need to be able to check for each patients when the results change from POS to NEG and from NEG to POS
and compare the dates of those two samples.
So far I was doing it manually which isn't viable for my sample.
I was trying to do something in SQL, but that didn't work out for me.
I also am trying to do some VBA or Excel formulas but I admit I'm getting kind of stumped.
I know I should do some for each cell loop or something but I really am lost.
I already grouped each patients info together using sub-totals and stuff.
Your help or at least pointers would be greatly appreciated :D
Here's an example of my data.
enter image description here
Use a formula like this, that in case the name is the same as the row before and the POS/NEG is different from the row before gives you the number of days in between, blank otherwise:
Of course it will give you an error if you try to use it on the 1st line, just enter it in the 2nd line and copy/paste in all the rest.
This should give you the basis for the rest of your analysis.

VBA - Graph by month

I am having issues trying to create code to make a graph that is dependent upon months. So I have Column A which is the beginning of the week date, i.e. 1/1/17. In Column B I have the count from that week of issues occurred. I would like to group together the count by month, using the Month function, so for January there are 37 issues, February - 23, etc. And then make a graph accordingly where the first month is titled January.
Eventually, I would like to similarly do this on a quarterly basis as well, but any help with the monthly issue first would be greatly appreciated. Here is a screenshot of the data which is located in Worksheets("Report").
First off, format your data as a table since that will make your life much easier. You will need to add headers to each column. This will make your data easier to read, and easier to maintain.
To format it as a table highlight the range, and then press CTRL+T. Make sure to check 'My data has headers'.
Good, now click inside the table, Insert > PivotTable. Select the destination. For rows you want Date, for values you want Sum of Value (where value is whatever you name your values column.
Then finally, check out this article for the whole rundown of Groupby: http://www.contextures.com/xlPivot07.html.
To be fair, there is an easy enough way of doing this without a PivotTable (adding a helper column for Month for example), but there's no need to reinvent the wheel. Additionally, if you want to add Qtr. eventually, you're better off familiarizing yourself with workhorses of excel.
Lastly, once you have taken the above steps, you'll likely find the Timeline slicer very helpful. You can use that to visualize specific periods on your pivot or chart.
Minor Note: This all assumes your dates are true dates. If they aren't, you'll likely run into more issues.

Excel change table Range for each month

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

SQL. Query for vba

I have a table that has more than one date fields (say six or seven) and I just want to retrieve only the dates that match today's date. Please help. Really appreciate it thanks
This is a very specific problem, so the best way to get the result you want is to code some part as an script on access.
For getting those rows where at least one date is the same as today's date, you should use something like this.
SELECT * FROM Table t
WHERE Date() IN (t.field1, t.field2, ...)
You should add all the fields you want to check inside IN clause.
On the Access for you should be able to process the data.

Merging cells horizontally across twelve columns

I am trying to merge cells horizontally, and I understand it can't be done dynamically by expression, so I'm looking for suggestions on a possible alternative way to accomplish it. I have 3 columns of data and then the next 12 columns are months. They enter the start month and then it's a rolling twelve month display. The user want's the top row of the heading to be the year, but merged. The second row of the heading is the month name. I've suggested to the user the easy task of merging after the export, but she also wants it exported to PPT and be ready to publish without modification. Any ideas?
enter image description here
This may seem like pretty simple stuff to you veterans, but I'm new to SQL and SSRS. So, to answer my own question, I ended up creating 12 rows that I can make visible according to the starting month of the rolling 12 months. I wasn't sure how that would work, but it is working great and I now have a foundation if I ever need it again.