COUNTIF function if day of week is Tuesday - excel

I need to count a column only if the corresponding cell in another column is a Tuesday. An example image is:
Initially, I was trying to use a COUNTIFS function paired with a WEEKDAY but I can't get it to work.
=COUNTIFS(B2:B32,TRUE,A2:A32,WEEKDAY(3))
or
=COUNTIFS(B2:B32,IF(A2=WEEKDAY(3),1,0))
Each unit needs to be counted on Tuesday every week. If they count a day before or after it's considered late. What needs to happen, is each unit needs to have a count of the number of days that they did count and then the number of days that they didn't count. In the past, I have accomplished this last part by a simple arithmetic formula based on the number of days in the month. In addition to the two counts, I also need any missed cells to be filled in with a red background.
The actual sheet has several tables in the same format ranging from 1 column to 65 columns.

Please try, in B34:
=SUM((WEEKDAY($A2:$A32)=3)*(B2:B32<>""))
entered with Ctrl+Shift+Enter and copied across to D34.
I am assuming you are able to count the number of Tuesdays in the relevant month and complete Row35 by deducting from that number the value in the cell immediately above.
Afterthought:
You have also what is really a completely separate question in your post (the red background) which I think is best handled with conditional formatting. Select B:D and in Conditional Formatting, New Rule... select Use a formula to determine which cells to format and under Format values where this formula is true: enter:
=AND(WEEKDAY($A1)=3,B1="")
Click Format..., select Fill and red, OK, OK.

You can insert an column B and fill it with the following formula:
=IF(WEEKDAY(A2)=3,1,"")
=IF(WEEKDAY(A3)=3,1,"")
...
Then you can count them with the following formulas:
Days counted =COUNTIFS(C$2:C$32,">0",$B$2:$B$32,1)
Days not counted =COUNTIFS(C$2:C$32,"",$B$2:$B$32,1)
You can hide the column B if you wish.

Related

Excel 2013 How to assign dates to cells

I'd like to assign dates to cells in a planner spreadsheet I have made.
Currently, the rows are months, the columns are days of the week, and each individual cells just have a number for the day of the month.
I don't want to display the full date in the cell, just have the cell "know" what date it is representing. One use of this could be to have the current day always highlighted in a different colour when opening the spreadsheet. Is this possible in Excel?
Looking at your question, the results would require to show multiple "dates" within the cell.
For January '16 for example, you would have 4 different type of dates as January has 4 Mondays (4;11;18;25). Is this what you're looking to achieve? Otherwise it is not possible to have excel figure out a single date unless you provide it with additional references in order to come up with a result.
Enter a date into a cell. Format the cell to show the part of the date you want to see. In the screenshot, column A contains full dates in each cell. A2 and down are formatted with the custom format code shown in column C
Excel still treats the dates as the underlying full dates in formulas, even though only parts of the dates are showing in the cell.

Conditional formatting based on date in another cell

I have text in cell A1 that I want to apply conditional formatting to based on the dates in cells A2:A5. That is if a date in A2:A5 is older than today I want A1 to be filled in red. If the date in A2:A5 is less than 30 days from today I want A1 to be orange. I have tried various formulas and just cant seem to get it to work. Appreciate any help. Thanks
You need to use conditional formatting (button in the home ribbon). Choose new rule and click 'Use a formula'. Enter the formula you want and click format and select the fill colour you want it to be. Click OK. You can do this multiple times with different colours and formulas.
So something like this would make A1 change if A2 was within 30 days:
=$A$2<($A$1-30)=TRUE
But what colour would A1 be if the dates in cells A2:A5 are a variety of dates? Eg. some are less than 30 days some more? The technique above is easy when comparing A1 to one cell. I am not sure you have thought about this or you just have not explained yourself properly.
EDIT:
If A1 is not a static date and you want formatting based on the current timeframe (eg B1 falls within 30 days) then use the Date Occurring feature. Examples of how you can use if below. So you are going to need 12 of these to cover B1:G1 with 30 days for orange and one day for red.

Excel measuring arithmetical average (counting blank cells)

I have a problem in Excel. I'm making a program to monitor the consumption of fuel per month. As I do not tank fuel every day, but only every couple days I'd like the program to measure aritchmetic mean for me.
This means it would take the last input and count all blank cells above (excluding my previous input) and measure the mean of fuel consumption in these days.
Example of how it should work:
[link to image] http://i64.tinypic.com/2dre87m.jpg
Edit: If anybody knows how to count number of empty cells between 2 inputs it would also suffice to me.
I was able to get your desired results using an array formula. Assuming your headings Day,Fuel, and Average are in cells A1, B1, and C1 respectively; copy and paste the following formula in cell C2 hit CTRL+SHIFT+ENTER and drag the formula down your column.
=IFERROR(IF(B2="","",(B2/(LARGE(IFERROR(MATCH($B$2:B2,$B$2:B2,0),""),1)-LARGE(IFERROR(MATCH($B$2:B2,$B$2:B2,0),""),2)))),B2)
It gave me a "formula omits adjacent cells" error, but we want to omit the cells below the target row on purpose, so just ignore the error. Hope this helps.
Try this formula:
=IF(B2="","",ABS(B2/(MATCH(0,B$2:B2,-1)-SUM(MATCH(0,B1:B$2,-1)))))
in C2 and copy down.
if cells in column B can contain string values then you can use this formula:
=IF(ISNUMBER(B2),ABS(B2/(MATCH(0,B$2:B2,-1)-SUM(MATCH(0,B1:B$2,-1)))),"")

How to write a custom formula so that Drag option does not take the cell formula in series?

I have an excel sheet with revenues generated daily. For Saturdays, sundays and other public holidays, the cell will be empty.
In another sheet I need to generate a weekly report where I need to show only the last generated revenue of that week. For example, a week starts from Monday and ends with Sunday. Satruday and sunday cells will be empty. So in Sheet2 A1 I should display Friday's revenue. Or if the current day is tuesday, it should show tuesday's revenue. I used the below formula to populate the value.
=IF('Sheet1'!A1<>"",IF('Sheet1'!B1<>"",IF('Sheet1'!C1<>"",IF('Sheet1'!D1<>"",IF('Sheet1'!E1<>"",IF('Sheet1'!F1<>"",IF('Sheet1'!G1<>"",'Sheet1'!G1,'Sheet1'!F1),'Sheet1'!E1),'Sheet1'!D1),'Sheet1'!C1),'Sheet1'!B1),'Sheet1'!A1),"")
However if I drag from cell A1 to B1 in sheet 2, it should consider week2 days, ie., column 8 to 14 and so on, but not 2 to 8.
So what would be the excel formula that I should be using?
Thanks in advance
Microsoft give this formula to determine which is the last cell filled with data:
=OFFSET(<StartCell>,0,MATCH(MAX(Range)+1,<Range>,1)-1)
Using OFFSET to get the range to check, and ROW() to determine which area, we can make the start cell OFFSET($A$1,(ROW()-1)*7,0) (assuming you have this in the 1st row, otherwise alter the -1 in the formula). The range becomes almost the same, but we tell OFFSET to return 7 cells: OFFSET($A$1,(ROW()-1)*7,0,7). We use $ to fix the cell, as we don't want to have to calculate offset from a variable position. This gives the full formula as:
=OFFSET(OFFSET(Sheet1!$A$1,(ROW()-1)*7,0),MATCH(MAX(OFFSET(Sheet1!$A$1,(ROW()-1)*7,0,7))+1,OFFSET(Sheet1!$A$1,(ROW()-1)*7,0,7),1)-1,0)
and this can be copied down as far as needed - you will start to get #N/A when the formula runs out of data to look at.
Any easier way of doing this might be to have a hidden row that looks to see if cell A1, B1 etc has a value in it, and to see if the next one is blank. And return a 1 when that statement is true, because that'll be the last one.
Then you just lookup the column that has a 1 in it using V or HLOOKUP.
It's easier to read, and you can use it across many more columns without having to make your formula bigger.

Excel highlight the cell of the matched date

I just want to know if it is possible for a a certain cell to be highlighted based on date whenever I put notes into another cell? As you can see at the image below, there are set of calendar with dates.
Now what I want to achieve is to highlight those dates whenever I put notes into another cell as the image shown below
Let's say I input a note in 5-Jan, Saturday the cell in image 1 ( January 5 ) will be highlighted with background color
Your problem consists of two parts. First you need to know how to use conditional formatting based on a formula, then you need to map your calendar cells to the corresponding notes cells.
Conditional formatting based on a formula is documented on several places on the web, for example here. For your case, I have created a screenshot of a simple example:
The difficult part (or hard labour, depending on which route you choose) in your case is to map all cells in your calendar to the corresponding cells potentially containing the note. So you need a way to calculate which day in the year a particular cell is.
I think you could achieve that via 12 different conditional formatting formulas, where you refer to the contents of "this" cell using INDIRECT("RC",FALSE) to get the day of the month, and then add the number of days before that month (for which you need 11 different constants). That result can be used as the index into your array of potential notes. So for February, the formula to calculate the day of the year becomes:
31+INDIRECT("RC",FALSE)
Using that number to check the row in your notes column (let's say they are in column A), the conditional formula for all cells in February becomes
=NOT(ISBLANK(INDIRECT("A"&(31+INDIRECT("RC",FALSE)))))
Then do the same thing for each month, where the constant (like 31) is different for each of them.
Note that using "RC" in INDIRECT() like this only makes sense in a conditional formatting formula.

Resources