Counting populating rows in Excel, but excluding first row - excel

I am trying to count the number of populated rows in Excel, but excluding the first row as this is used as a header. ie. I want to start counting from the second row.
The following works to count populated rows, including the first row:
=COUNTIF(Books!A:A, "<>")
Logically, this is what I want, but it doesn't work in Excel:
=COUNTIF(Books!A2:A, "<>")
Seems like this should be simple? Am I missing something obvious? Thanks in advance!

There are two possibilies:
Use the limit of Excel by entering the last possible row:
=COUNTIF(Books!A2:A1048576;"<>")
If the Header is always there, you could just substract it from the result:
=COUNTIF(Books!A:A, "<>")-1

You need to count until last row, so if your data finish in row 20, then:
=COUNTIF(Books!A2:A20, "<>")
But if your data change rows quantity very often sometimes 20, sometimes 40, sometimes 10, I suggest you use a Table (a Listobject) because it works as a dynamic range:
Create and format tables
My formula is:
=COUNTIF(Table1[Book Name],"<>")
Where Table1[Book Name] equals to range A2:A9 in this case. But if you add more data, Table1[Book Name] will refer to new range, and the formula will autoupdate :)
Using full qualified ranges as A:A may work and it's easy to use but it's a waste of resources checking a million cells every time you calculate. Besides, if you use a lot of formulas using full columns, it may overcharge the file and the time recalculations needs.

Related

Need to create an array formula where the target ranges are not in fixed locations

Currently I am using the following formula in successive rows on a sheet named Data
{=IFERROR(SMALL(IF($Q$2=DMS!$I$1:$I$99999,ROW(DMS!$I$1:$I$99999)-ROW(DMS!$I$1)+1),1),"")}
{=IFERROR(SMALL(IF($Q$2=DMS!$I$1:$I$99999,ROW(DMS!$I$1:$I$99999)-ROW(DMS!$I$1)+1),2),"")}
{=IFERROR(SMALL(IF($Q$2=DMS!$I$1:$I$99999,ROW(DMS!$I$1:$I$99999)-ROW(DMS!$I$1)+1),3),"")}
...
For a total of 30 rows to determine the first 30 rows within Sheet DMS column I that match the value in my sheet 'Data' cell Q2.
I am trying to find a way to either recreate the above arrays, or an alternate solution to using the arrays, when the searched range is no longer going to be a fixed location. Essentially what was in column I could be in column J tomorrow and H the next day and back to I for the next 3 days. I will be able to tell where it is by the column header, so I do have one static point of reference, even if it is not in a fixed column.
Try this formula. It looks for a column with the text "TheKey" in the first row of columns A to Z and will then perform the match on the values in the found column.
In Excel 365, you can just hit enter, in earlier versions, you need to use Ctrl+Shift+Enter
=IFERROR(SMALL(IF($Q$2=INDEX(dms!$A$1:$Z$9999,1,MATCH("TheKey",dms!$A$1:$Z$1,0)):INDEX(dms!$A$1:$Z$9999,9999,MATCH("TheKey",dms!$A$1:$Z$1,0)),ROW($A$1:$A$9999)),ROW(A1)),"")
In Excel 365, you can avoid the duplication of the Match function by applying the new Let() function and re-using the result. Like this:
=LET(myColumn,MATCH("TheKey",dms!$A$1:$Z$1,0),IFERROR(SMALL(IF($Q$2=INDEX(dms!$A$1:$Z$9999,1,myColumn):INDEX(dms!$A$1:$Z$9999,9999,myColumn),ROW($A$1:$A$9999)),ROW(A1)),""))
I removed the -ROW(DMS!$I$1)+1 because that does not do anything, really. Just subtracts 1 and then adds 1 again.
I also replaced the hard-coded number for subsequent rows (1, 2, 3, etc) with Row(A1), which will evaluate to 1 in the first row of the formula and when copied down will turn into 2, 3, 4, etc without having to adjust the formula for each row.
You need to combine several advanced functions. First of all, you need to locate that header, because it's your only static point.
You can locate your static header using:
=CELL("address";INDEX(DMS!$A$1:$M$1;;MATCH("STATIC HEADER";DMS!$A$1:$M$1;0)))
In this case, it will return this text: [Libro1]DMS!$I$1
It's the complete path to cell.
Now you need to combine that string, with OFFSET to get a reference to that column and get like 99999 rows of data. ISsue here is OFFSET does not work on different worksheets from active one, so you need to combine it with INDIRECT first to get a reference to range in sheet DMS:
INDIRECT function
OFFSET function
So then a formula like next one will return a reference of 1 column and 99999 cells where your static header is:
OFFSET(INDIRECT(CELL("address";INDEX(DMS!$A$1:$M$1;;MATCH("STATIC HEADER";DMS!$A$1:$M$1;0))));0;0;99999;1)
So now you can combine all of these into a really huge formula:
=IFERROR(SMALL(IF($Q$2=OFFSET(INDIRECT(CELL("address";INDEX(DMS!$A$1:$M$1;;MATCH("STATIC HEADER";DMS!$A$1:$M$1;0))));0;0;99999;1);ROW(OFFSET(INDIRECT(CELL("address";INDEX(DMS!$A$1:$M$1;;MATCH("STATIC HEADER";DMS!$A$1:$M$1;0))));0;0;99999;1)));ROW()-5);"")
Notice I've deleted the ROW(DMS!$I$1)+1 because that's always equal to 0, so not needed. I addedd in SMALL function the part ROW()-5) so I can drag down (i'm testing in row 6 and dragging down. No need of those 1, 2, 3 you input manually). Adapt this part to your needs.
Notice that if STATIC HEADER is in a different column, the formula still works.
I've uploaded a file do my Gdrive in case you want to see how it works, because copying so many functions can be crazy.
https://drive.google.com/file/d/16Y6mQ_hiu1TKLXhTUgvq8tN67eHQKtVb/view?usp=sharing

Automate concatenation process

Here I am stucked with one excel issue where i want to concatenate from column F till column I where the logic is when the benchmark column A3 (for example) is blank it need to concatenate column F till column I till there is a value at column A4.and this logic need to automatically concatenate the mentioned column till there is a value under the benchmark column. currently i need to keep change the concatenate range in order to concatenate it fully with the logic. Appreciate if anyone can help me out.
Below image shows how i am doing manually which very time consuming
You can use the MATCH function (with a wildcard) to find the next non-blank row; and use that in an INDEX function to detect the range to concatenate.
Assuming your data starts in A3 and the lowest possible row is row 1000 (change the 1000's in the formula below if it might be much different:
J2: =IF(A2="","",CONCAT(INDEX(F2:$I$1000,1,0):INDEX(F2:$I$1000,IFERROR(MATCH("*",A3:$A$1000,0),1000-ROW()),0)))
Note: It is possible to also develop solutions using INDIRECT and/or OFFSET. Unfortunately, these functions are volatile, which means they recalculate anytime anything changes on your worksheet. If there are a number of formulas using these functions, worksheet performance will be impaired. INDEX and MATCH are non-volatile (except in ancient versions of Excel - pre-2003 or so)
The OFFSET-function would come on handy here. One solution is to do it like
This works in my worksheet.
Cell Q6 just defines the number of rows downwards that the MATCH-function is checking for the next "HEADER1" value. If "HEADER1" is found, the MATCH-function returns how many rows down-1. If no "HEADER1"-value is found within that range, that value is then the number of rows used.
If the first column also has "HEADER2" and so on, you can add the MID-function to both references inside MATCH to limit which part of the string are to be searched for.
I tried to adjust the references properly to fit your sheet, but I may have missed something:
=IF(ISBLANK($B2),"",CONCAT(OFFSET($B2,0,0,IFNA(MATCH(MID($B2,1,6),MID(OFFSET($B2,1,0,$B$1),1,6),0),$B$1),4)))

Using tables and column titles in VLOOKUP

I'm having a very difficult time with transitioning my VLOOKUP statement from simply referencing sheets and ranges (which work like a charm), to instead using table and column names.
I'm trying to make the VLOOKUP a bit more robust as the sheet where it is pulling from will constantly be changing data, so column numbers will change frequently. Thus, I'd like to just reference a column by its name.
I have converted the source data sheet to a table.
I have named all columns appropriately and double checked spelling.
This VLOOKUP works great (currently):
=VLOOKUP(E6,'Costs'!$A$2:$AE$84,19,FALSE)
However, what I would like to do is make it look this:
=VLOOKUP(E6,tblCosts[Order Number],tblCosts[June 2017], FALSE)
I have been fiddling with also trying to use MATCH which is not working either:
=VLOOKUP(E31,tblCosts[Order Number],MATCH(F4,tblCosts[June 2017],FALSE),FALSE)
UPDATE
This formula now works but it is returning the order number...not the cost for the month.
=VLOOKUP(E31,(tblCosts[Order Number]),(tblCosts[June 2017]),FALSE)
Normally I would keep trying this myself...but I am feeling overwhelmed and have been trying for hours. Any advice would be great.
Thank you!!
This should work for you:
=VLOOKUP(E31,tblCosts[#All],COLUMN(tblCosts[Jun-17]),false)
The COLUMN(TblCosts[Jun-17]) returns the column number of the field you want.
The VLookup searches the first column of tblCosts[#All] - (all the data in the table) for the data (in E31) and returns the data in the column you want.
This formula will continue to work even if you add columns or rows to the data.
Make sure that any heading which looks like a date in your spreadsheet eg "Jun-17" is stored as Text and not as a Date, as it will not match the string "Jun-17" when you use VLookup.
=VLOOKUP(E37,tblCosts[#All],match("Jun-17", tblCosts[#Headers]),FALSE)
This match is looking for the column name in all column headers and will return the number of columns to the right of the first column rather than the column number in the sheet. This avoids having to use COLUMN(tblCosts[Jun-17]) - COLUMN(tblCosts[Order Number]) + 1 when your table doesn't start in column A.
Ref: https://www.excel-university.com/vlookup-hack-4-column-labels/

Excel: Get values in non-adjacent cells based on multiple criteria

I have an excel sheet sort of like this:
I'm trying to figure out how to get the totals in cells B1 through B4.
I tried INDEX-MATCH, where I tried to match the words in A1:A4 with the words in row 7, get the numbers relative to them, and then sum them, but it was a lot of Google searching and stabbing in the dark -- every attempt returned an error.
I also tried to INDEX-MATCH the words in A1:A4 with row 7, and then nest a VLOOKUP in there where it'd get the number relative to "visits:" but that didn't work at all either.
Is INDEX-MATCH even the correct function? Any help would be much appreciated, I'm not even sure what to Google anymore.
EDIT: I need to use a search function of some kind, like the INDEX-MATCH method, rather that static formulas because the sheet will change periodically and I don't want to have to update the formula every time I add an animal.
Your data table is unusual in structure.
However, if you are gong to keep a fixed rule such that the number of visits is always offset 2 rows and 1 column from the animal type(and that itself is always in row 7), you could do:
In B1:
=SUM(IF($A$7:$AAA$7=$A1, $B$9:$AAB$9, 0))
Confirm with Ctrl-Shift-Enter, and then copy down..
DOes this work?
=SUM(IF($B$7=A1,$C$9,0),IF($D$7=A1,$E$9,0),IF($F$7=A1,$G$9,0),IF($H$7=A1,$I$9,0))
I'm not sureto have fully grasped your challenge. Yet it seems the following solution would work:
Add the following formula in each box where the number of visits is added as
=+SUMIF($A$1:$A$end;animal;$B$1:$B$end)
Where end is a number of the last cell in the first and second columns data contain the data.
And animal is the cell that contains the name of the animal.
Therefore in your simple example, the formulas on cells C9;E9;G9 and I9 would be respectively:
=+SUMIF($A$1:$A$4;B7;$B$1:$B$4) ; =+SUMIF($A$1:$A$4;D7;$B$1:$B$4); =+SUMIF($A$1:$A$4;F7;$B$1:$B$4) and =+SUMIF($A$1:$A$4;H7;$B$1:$B$4).

excel function to find last number in column

I record the value of my stocks each day in columns and it is a long spreadsheet. In the top cell of each column, I want to use a function that will display the last entry in the column automatically. I've tried the Index function and the Index function combined with the Counta function with no success. Any suggestions?
Try using LOOKUP, assuming at most 1000 rows of data (adjust as required) use this formula in A1 to get the last number in A2:A1000
=LOOKUP(9.99E+307,A2:A1000)
You can have blanks or any other data in the range (even errors) and it will still return the last number
Try this for Column A, resp. Cell A1:
=OFFSET(A$2;ROWS(A$2:A$101)-COUNTBLANK(A$2:A$101)-1;0)
This example is for a maximum of 100 rows of data (2 - 101). You may replace 101 by any higher number according to the size of your sheet.
Please note that there may be no blank cells in the middle of the list.
The answer Jens Fischer provided worked excellently and also translated well to google sheets whereas other solutions have not. I made one small change; by using A$1 as the reference I didn't need the -1 at the end of the formula.

Resources