IF all cells in a range are the same, excluding blank cells - excel

I have a table to calculate the price of a project, where one column is the description of an element of the project followed by a column for its unit (usually hours), the price per unit, number of units, and the final price,
sort of like this:
My question really only involves the highlighted cells. Im making a template, and I add elements to the table as I go along, so some rows are left blank, but I want the total number of hours to be displayed in D7 (easy enough, =SUM(D2:D6)), but my problem is that some of the elements aren't written per hour (eg. row 4), so I want the total to only show up if all the values are for hours. Essentially:
IF all values in row B are "Hours", then sum of row D, else "")
I guess in short, is there a formula I can use that would return TRUE if all the values in a range are the same, excluding blank cells?
Thanks.

As per your last comment, you can try:
Formula in D7:
=IF(COUNTIFS(B2:B6,"<>Hours",B2:B6,"*")=0,SUM(D2:D6),"")

Related

min & max value in range in loop

I've faced huge problem with my macro. I have data that contains colums with quantities and values of stock like this:
What I'm trying to achieve is:
to go through every row until the very last, locate quantity (colums with Q letter) and values (colums with V letters) below 0, then adding these quantities below zero to the maximum quantity within the row and adding these values below 0.
to find values within age category for every row that have no corresponding quantity (see cell B4 as example) and add these values to the maximum value within the row.
Why VBA for something you can achieve with a formula?
Let me show you how I calculate the maximum of a list of cells, referring to a column, whose name starts with a "V":
=MAXIFS(A2:F2,A1:F1,"V*")
Screenshot:
Explanation:
Take the maximum of the values on the second row (A2:F2)
The criteria you need to take into account refer to the first row (A1:F1)
The criteria is that it should start with a "V".

Calculating Averages of every 6th cell VBA

I'm looking to calculate the average of a series of cells across multiple tables on the same spreadsheet.
Each manager has a table and in each table, there are a number of statistics e.g. Total Activity, Outbound Calls & Credit. Each table is situated one under the other e.g. Danny's table might be situated on rows 1- 5, Ann's 7-12, Katie's 14-19. I need to find the average for each statistic and output it to my summary page.
I've tried using Application.WorksheetFunction.Average but could not get it working as the range is scattered among various rows. I do however know that each variable appears in every 6th row so I tried For i = 2 To lastRow Step 6 which outputted the values into cells and calculated the averages based on that cell range but I'd rather have something more direct if possible.
Could anyone offer a valid solution to this?
Sample of data beneath. looking to get the average for each of the 4 variables.
Alternative 1
If there are other values than the values you want an average of in column B, you can use SUMPRODUCT.
Enter this formula in any cell in any other column than column B. It will calculate an average of every 6th value starting on row 2.
=SUMPRODUCT(B:B*1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2))/SUMPRODUCT(1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2))
B:B Array of all values in column.
1*NOT(ISBLANK(B:B)) Array of 1 or 0, 1 on non blank cells in column B, 0 for blank cells.
1*(MOD(ROW(B:B),6)=2) Array of 1 or 0, 1 on row 2, 8, 14 and so fourth
SUMPRODUCT(B:B*1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2)) sums all non blank cells in column B on every 6th cell starting at row 2.
SUMPRODUCT(1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2)) counts all non blank cells in column B on every 6th cell starting at row 2.
To speed up the formula you can replace B:B with for example B1:B100 depending of the number of rows that have values.
Alternative 2
If there are nothing but values you want an average of, then you can use SUBTOTAL as suggested by Dominique. =SUBTOTAL(1,B:B)

Add Number of Empty Cells in a Column Limiting To Last Data Cell

Looking to add a cell function that counts the number of blank cells in a column, but only to the bottom row of data. Each row in my spreadsheet is a customer order and the sheet keeps track of order assembly progress, each task is grouped into a column and if the cell is blank it means it is yet to be finished.
Tasks include columns F-K, other rows will not be counted
Goal: Number of incomplete(Blank) tasks in a column will be shown as a number at the top of the sheet.
Problem: When using =COUNTBLANK (x3:x) The function counts all blank rows to the bottom of the sheet, Need to limit this to the bottom of the data. That number changes depending on how many orders are on the sheet so this number needs to be adaptive to the bottom of the data(Last order)
Link to copy of Sheet: Order Priority Sheet
Any Additional Information, misunderstandings, or questions please ask. I understand if my descriptions were not clear and would be more than happy to help you help me!
Try:
=COUNTBLANK($A$3:INDEX($A:$A,LOOKUP(2,1/(LEN($A:$A)>0),ROW($A:$A))))
adjust the column references for your desired column
This part of the formula:
LOOKUP(2,1/(LEN($A:$A)>0),ROW($A:$A))
returns the last row number in column A that appears blank.
However, if, for example, you wanted to count all of the blanks in the range F3:Kn where n is the last used row in column A, then try this modification:
=COUNTBLANK($F$3:INDEX($F:$K,LOOKUP(2,1/(LEN($A:$A)>0),ROW($A:$A)),6))
If you just want to count each column separately, again, using column A to determine the last relevant row, then, (for column F):
=COUNTBLANK(F$3:INDEX(F:F,LOOKUP(2,1/(LEN($A:$A)>0),ROW($A:$A))))
and fill right
Column A seems to be a column where the last populated cell defines the extents of the data. Dates are considered numbers so the row with the last populated date in column A would be,
=match(1e99, a:a)
To count the blanks in F3:<last cell>,
=countblank(f3:index(f:f, match(1e99, $a:$a)))

Comparing Date and Time between Cells and Create a versioning column on which appeared first

screen shot of excel
Hello,
I have 3 columns in my excel sheet. Column A is item number, Column B is file Name, Column C is the date/time that file was modified(it is called matched in excel). I created a column D called versioning by comparing date and time of files with the same item number, right now I am doing this manually, Is it possible that it can be automated?
Thanks in advance!
Assuming your data has column headings in row 1, so data begins on row 2 and version begins on cell D2 and, just say your data stretches down to, say, row 100, you could use the following formula in cell D2:
D2: =COUNTIFS($A$2:$A$100,A2,$C$2:$C$100,"<="&C2)
Basically, you're saying For every file with the same Item number, how many have a date/time less than or equal to this row's?
That will, in effect, give you a version number.
As requested in the comment, to explain this formula in a bit greater depth, let's break it down:
Heading Match:
CountIfs($A$2:$A$100,A2:
This portion is saying "Only count if the value in $A$2:$A$100 = the value in A2" - Therefore, only count rows where the item number is the same as the one in the current row
Versioning:
CountIfs($C$2:$C$100,"<="&C2:
This portion is saying "Count the number of dates LESS THAN OR EQUAL TO C2" - Therefore, how many dates do we have that are less than or equal to the date in this current row.
So, if you put them both together, you get:
1) Only count a value with the item number is the same as this current row
2) And, of those, how many rows contain a date that is less than or equal to the date contained in the current row.
That, in effect, gives you a version number for every row.
Hope that does it.
Try this in your cell D2: (you may need to make the ranges bigger):=1+SUMPRODUCT(($A$2:$A$18=A2)*($C$2:$C$18>C2))

How to get the highest values from 2 columns in Excel?

I have a design software which extracts data in to an Excel sheet format
The output is divided into 2 columns, each of these columns has more than 1000 rows.
To make use of this data I need to summarize it to a maximum of the 5 highest values from both of the 2 columns. Therefore, this doesn't mean that it's the maximum of one column and its corresponding value, but it may mean that the 2nd largest value of column 1 & the 4th largest value of column 2.
For example ( if we quoted some of the output data):
The values i should pick here are:
If there is any possible way to achieve that, it will be great
Thanks ..
example file: http://goo.gl/UIEFEv
example file 2: http://goo.gl/VSvuVf
Here's a formula solution. I used 20 rows and extracted the rows which contain the top 5 for each column - you can extend to as many rows as required.
With data in A1:B20 use this formula in D1 confirmed with CTRL+SHIFT+ENTER and copied across to E1 and down both columns:
=IFERROR(INDEX(A$1:A$20,SMALL(IF(($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)),ROW(A$1:A$20)-ROW(A$1)+1),ROWS(D$1:D1))),"")
Note: there are only eight rows extracted because some of the rows contain values in the top 5 for both columns. I added the highlighting in colums A and B to more clearly illustrate
see screenshot below
Edit:
From the comments below it seems that you want a combination of rows which contain the highest value for that column....and rows which contain the highest total for both columns.
In the original formula there are two conditions joined with "+", i.e.
($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)
The "+" gives you an "OR" type functionality, e.g. in this case rows are included if individual values are in the top 5 in that particular column. You can add other conditions, so if you want to also add any rows which are in the top 5 considering the total of both columns then you can add another "clause", i.e.
($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5)+($A$1:$A$20+$B$1:$B$20>=LARGE($A$1:$A$20+$B$1:$B$20,5))
....and including that in the complete formula you get this version:
=IFERROR(INDEX(A$1:A$20,SMALL(IF(($A$1:$A$20>=LARGE($A$1:$A$20,5))+($B$1:$B$20>=LARGE($B$1:$B$20,5))+($A$1:$A$20+$B$1:$B$20>=LARGE($A$1:$A$20+$B$1:$B$20,5)),ROW(A$1:A$20)-ROW(A$1)+1),ROWS(D$1:D1))),"")
You could refine that further by using combinations of + and * (for AND), e.g. for the new condition you might only want to include rows with a total in the top 5 if one of the single values is in the top 10 for that column...
Explanation:
The above part shows how you can use + for the OR conditions. In the formula if those conditions are TRUE then the IF function returns the "relative row number" of the range (using ROW(A$1:A$20)-ROW(A$1)+1).
SMALL function then extracts the kth smallest value, k being defined by ROWS(D$1:D1) which starts at 1 in D1 (or E1) and increments by 1 each row.
INDEX function then takes the actual value from that row.
When you run out of qualifying rows SMALL function will return a #NUM! error which IFERROR here converts to a blank
The question is a little unclear but if what you mean is to get the 5 highest values of Column A and their corresponding values in Column B then the five highest values in Column B and the corresponding values in Column A then the (non automated) solution is pretty simple.
Click on a cell with a header title in it.
Click on 'Data' in the top menu.
Click on 'Filter' in the 'Sort & Filter' section.
Click on the button on Column A - select 'Sort Largest to Smallest'
Grab the top five values from both columns then click on the button in column B and repeat.

Resources