I have a work sheet in which there are several cells with a specific entry - let's say "A". These are not all in the same rows/columns. After each cell is a date.
I need to count the number of cells containing "A" which also have a specific date in the cell immediately to its right. I've tried combinations of Countifs and Indirect, with no success. How can I achieve this?
This counts the number of times that there is A in column A and 1 in column B
=SUMPRODUCT(($A$1:$A$5="A")*($B$1:$B$5=1))
This outputs in cell D1
Not too difficult.
I have created a sample sheet with 8 rows and 5 columns of data.
See below, the formula in cell C12 counts the number of occurrences where the a cell with a date of October 31, 2017 is directly to the right of a cell that contains the text A.
If you want more info as to how this works, read on:
When searching for cells that contain A, you don't search in the last column of the data (in this case, column E) because it is impossible for a column to the right to have any date in it. This is why a portion of the formula says A1:D8="A" instead of A1:E8="A". This is the same reasoning why we start searching for a date in column B rather than column A in the formula.
You can achieve this with a helper row. Add additional row on top of your Worksheet. In cell "A1" enter formula below.
=COUNTIFS(A2:A2000,"A",B2:B2000,"YourDate")
Drag this formula to the rightmost of where you have data, then simply sum all values returned by formula.
Related
I want to define a dynamic range that will expand the rows and columns of my range whenever a new row or column is inserted. My current formula does not want to expand to cell $T$13. My headers start in row $M$7. How can I adjust my formula?
Formula Being Used
=OFFSET(Sheet1!$M$8,0,0,COUNTA(Sheet1!$M:$M),COUNTA(Sheet1!$1:$1))
I need my range to expand to cell $T$13
Right now, your formula counts the number of text values in column M.
That is not a robust approach because column M contains only five text values, but columns S and T have many more values.
If you don't know which column may have the most number of entries, you can introduce a helper cell in each column that counts the number of entries below. I suggest you insert a new row 2. In column M, for example, put a formula in M2
=counta($M$3:M$99999)
Copy that formula across to column T.
Next you can evaluate which of the columns has the largest number
=max(M2:T2)
This can be plugged into your original formula like this:
=OFFSET(Sheet1!$M$8,0,0,max(M2:T2),COUNTA(Sheet1!$1:$1))
So now, instead of just looking at how many rows are in column M, the formula uses the maximum number of rows in the columns M to S.
You can now hide row 2 if it upsets your worksheet design.
Edit: the mere count of text values with CountA will ignore blank cells and will return incorrect results. You really need a formula to find the row number of the last populated cell in each column.
This should really be a new question, but here goes
If the column has number values you can use
=MATCH(99^99,B5:B999,1)
If the column has text values you can use
=MATCH("zzz",C5:C999,1)
Adjust your ranges accordingly.
I ended up using the solution mentioned by #tevlyn.
In range$M2:$T2
I have the follolwing formula =IFERROR(MATCH(99^99,M$8:M$999,1),0).
I've added IFERROR because my data doesn't always have data stretched to $T2.
I then defined my range in name manager using:
=OFFSET(Sheet3!$M$8,0,0,MAX(Sheet3!$M$2:$T$2),COUNTA(Sheet3!$1:$1))
This still works even if there are blanks in between the range.
I am creating a reading list that has the day in column a and the required reading in column b for that day. in column c I write the day the reading is completed.
I want to have a cell display the required reading from the row that has the first blank cell in column c.
I hope this makes sense.
I know I'll have to use indirect, because I have a cell with the required reading from today in another cell using =INDIRECT("B"&MATCH(TODAY(),A:A))
The way I understood your question is:
- You have dates in Column A
- Column B has corresponding readings
- Column C is reading completion date that can be blank
So what you want is the first reading from Column B for dates in Column A which are same as today's date where Column C is blank
If my understanding is correct the following array formula should work for you.
=INDEX($B$2:$B$21,MATCH(1,($A$2:$A$21=TODAY())*($C$2:$C$21=""),0))
This is an array formula you'll have to commit it by pressing Ctrl+Shift+Enter
See the image for reference (rows with matching date in Column A i.e. equal to today's date are highlighted):
This result can also be achieved using your formula with some change as:
=INDIRECT("B"&MATCH(TODAY(),(A1:A21)*(ISBLANK(C1:C21)),0))
Again this is an array formula.
But as #Gary'sStudent mentioned in his answer, its always better to avoid INDIRECT function.
This will give the row containing the first blank in column C:
=MATCH(TRUE,INDEX(ISBLANK(C:C),0,0),0)
So to get the equivalent cell in column B, use:
=INDEX(B:B,MATCH(TRUE,INDEX(ISBLANK(C:C),0,0),0))
Thus we avoid INDIRECT(). See:
Daily Dose
So at the top of my Excel sheet I have 2 cells, A2 and B2, where people can enter a starting and ending date.
On a seperate sheet I have an enormous list of starting and ending dates in columns A and B, and corresponding data for each of these 'events' in columns D through G. I need my function to copy all rows where the starting date falls between the two specified dates, and copy the data to the first sheet, in cells A4 - G4 through A100 - G100. (I just chose 100 as a large number, to make sure the area where the data gets placed is large enough)
I'm guessing this function I need includes the INDEX function, but I only know how to use it to look up one data cell at a time, not how to copy an entire range of cells.
Can anyone help?
No helper columns required.
Enter this formula into cell A4:
=IFERROR(INDEX(data!D$2:D$9999,SMALL(IF((data!$A$2:$A$9999>=$A$2)*(data!$A$2:$A$9999<=$B$2),ROW(data!$D$2:$D$9999),9E+99),ROW(1:1))-1),"")
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
Now copy the formula to the range B4:D4.
Now copy the A4:D4 to the range A5:D100.
That's it.
Let's say Column C in the data sheet is blank, and free to add a formula.
Let's also assume that the data begins in row 2.
Then the following formula can be put in C2 & copied down:
=IF(AND(A2>=Sheet1!$A$2,B2<=Sheet1!$B$2),C1+1,C1)
Basically it is saying that if the beginning date of the current record is greater than or equal to the date the user is looking for, and the ending date is likewise within range, iterate the record, otherwise not.
At this point the user sheet can have a simple VlookUp as follows:
In D1: =VLOOKUP(ROW($A1),Sheet2!$C:$G,COLUMN(B$1),0)
Copy this across to G and down however many rows you like.
I am trying to display the total sum of all the numbers for a particular column. I want the sum to be displayed above the column as follows:
21 30
A B
6 5
6 10
6 10
3 5
I know I can sum the values and display it at the bottom of the column using =SUM(A3:INDIRECT("D"&ROW()-2)), however I am not getting a way to display it at the top of the column.
Please guide.
Based on the comments and the previous answers I suggest following formula, entered in cell A1:
=SUM(OFFSET(A$2,0,0,ROWS(b:b)-1))
You can then copy/paste to the right till second last column.
You could also modify your formula in A1 like this to achieve the same:
=SUM(INDIRECT("A2:A"&ROWS(A:A)-2))
But then you cannot copy/paste to the right...
A more general approach with your idea would be:
=SUM(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROWS(A:A),COLUMN())))
You can then copy/paste to the right till last column.
Some explanations:
Both formula sums up every value in the range from A2 till the bottom of column A (i.e. for Excel 2010 this would be A2:A1048576)
It doesn't matter if there are blanks or cells without value; the formula sums up only the numbers
I put A$2 and B:B in the OFFSET formula to avoid circular references, since I'm writing in cell A1 and I cannot write A$1 nor A:A
With the INDIRECT formula you don't have to worry about circular references
Further commenting (sorry, I don't have the credits to comment at the right place under the question):
Phylogenesis formula =SUM(A3:A65535) could also do the work, isn't it?
Didn't understand your question at first, because you talk of "sum of all the numbers for a particular row" but then you sum columns, isn't it?
When I'm doing something like this, I prefer to not include any empty cells beneath the range I'm summing, because I've had errors in the past as the result of including them (usually because there's a cell way down in the column somewhere that I'm not expecting to have a value). I'm assuming that A & B are your column headers. Assuming that, here is how I would do it. This is your formula for cell A1:
=SUM(OFFSET(A$1,2,0,COUNTA(A$3:A$65535)))
Explanation
I'm updating this with a brief explanation, per the OP's request.
According to ExcelFunctions.net:
The Excel Offset function returns range of cells that is a specified number of rows and columns from an initial supplied range.
The function reference for OFFSET is:
=OFFSET(reference, rows, cols, [height], [width])
What this formula does is create a dynamic range based on the number of cells in the selection, relative to cell A$1. This is an offset of two rows and no columns, which starts the range at A$3. The height of the range is the total number of filled cells in the range A$3:A$65535. The assumption here is that there are no blank cells in the range, which there were not in the sample data.
I've been working on a excel problem, that I need to find an answer for I'll explain it below.
I've Table01 with the Columns :
Group No
Name
Price
I've Table02 with the columns:
Group No
City
Code
I've merged two tables of Table01 & Table02 as shown in the Image03 , But without order.
But,as you see Group No Column is similar in both tables.
What I need is to get the matching rows of Table01 & 02 considering 'Group No' Column.
The Final result is to be seen as the final image.
Is there a way to do this with excel functions ?
Thank You!
Put the table in the second image on Sheet2, columns D to F.
In Sheet1, cell D2 use the formula
=iferror(vlookup($A2,Sheet2!$D$1:$F$100,column(A1),false),"")
copy across and down.
Edit: here is a picture. The data is in two sheets. On Sheet1, enter the formula into cell D2. Then copy the formula across to F2 and then down as many rows as you need.
Teylyn's answer worked great for me, but I had to modify it a bit to get proper results. I want to provide an extended explanation for whoever would need it.
My setup was as follows:
Sheet1: full data of 2014
Sheet2: updated rows for 2015 in A1:D50,
sorted by first column
Sheet3: merged rows
My data does not have a header row
I put the following formula in cell A1 of Sheet3:
=iferror(vlookup(Sheet1!A$1;Sheet2!$A$1:$D$50;column(A1);false);Sheet1!A1)
Read this as follows: Take the value of the first column in Sheet1 (old data). Look up in Sheet2 (updated rows). If present, output the value from the indicated column in Sheet2. On error, output the value for the current column of Sheet1.
Notes:
In my version of the formula, ";" is used as parameter separator instead of ",". That is because I am located in Europe and we use the "," as decimal separator. Change ";" back to "," if you live in a country where "." is the decimal separator.
A$1: means always take column 1 when copying the formula to a cell in a different column. $A$1 means: always take the exact cell A1, even when copying the formula to a different row or column.
After pasting the formula in A1, I extended the range to columns B, C, etc., until the full width of my table was reached. Because of the $-signs used, this gives the following formula's in cells B1, C1, etc.:
=IFERROR(VLOOKUP('Sheet1'!$A1;'Sheet2'!$A$1:$D$50;COLUMN(B1);FALSE);'Sheet1'!B1)
=IFERROR(VLOOKUP('Sheet1'!$A1;'Sheet2'!$A$1:$D$50;COLUMN(C1);FALSE);'Sheet1'!C1)
and so forth. Note that the lookup is still done in the first column. This is because VLOOKUP needs the lookup data to be sorted on the column where the lookup is done. The output column is however the column where the formula is pasted.
Next, select a rectangle in Sheet 3 starting at A1 and having the size of the data in Sheet1 (same number of rows and columns). Press Ctrl-D to copy the formulas of the first row to all selected cells.
Cells A2, A3, etc. will get these formulas:
=IFERROR(VLOOKUP('Sheet1'!$A2;'Sheet2'!$A$1:$D$50;COLUMN(A2);FALSE);'Sheet1'!A2)
=IFERROR(VLOOKUP('Sheet1'!$A3;'Sheet2'!$A$1:$D$50;COLUMN(A3);FALSE);'Sheet1'!A3)
Because of the use of $-signs, the lookup area is constant, but input data is used from the current row.