CountA function for a specific value in an external workbook - excel-formula

i am looking to count how many Product 1 is in the specified range on a different workbook. currently what i have is this.
=counta('path[file.xlsx]sheet!E2:E301,"Product 1")-1
It only returns me the filled range which is 300. What am I missing?

COUNTA counts all cells in range that are not empty and its only argument is a range that should be checked,so you'll either have to create a helper column with a formula that will return blank cell if the record is not Product 1 or use COUNTIF(range,criteria) but you'll need to open both workbooks to update the values.

Related

Excel count non emtpy cells

I have a string in the cell A1 in sheet name Sheet 1.
I now use the MATCH function to find the string of cell A1 in the range A1:Z1 of a different sheet.
That works fine so far. The function returns the column number. (let's say 5, in column E)
My overall goal is to determine how many non-empty cells I have in a certain column. For that, I can use the COUNTA formula which expects a range as parameter. My problem is that I do not know how to convert the number of a column into a valid range without using VBA.
Manually I would do COUNTA(E:E) but I need to create a range for a numbered column like 5.
Thx.
Use INDEX:
=COUNTA(INDEX(Sheet2!A:Z,,MATCH(A1,Sheet2!A1:Z1,0)))

Excel Sum Formula With Multiple Criteria

So I'm having a problem with summing some data in a range with multiple criteria. Take the data below as an example:
I would like to sum all numbers where: Name = Bob AND the top row is equal to 02/01/20.
The current formula i have is with a SUMPRODUCT, but i'm not sure if it's the solution
=SUMPRODUCT((Names="Bob")*(Dates="02/01/2020")*Values)
Where Names is a named range for my names, Dates is a named range for my dates and Values is a named range for all my values in the table. However, the formula keeps resulting in "#VALUE!".
Any ideas anyone?
You need to turn your date string into a date value. So try:
=SUMPRODUCT((Names= "Bob")*(Dates=--"02/01/2020")*Values)

Reference named ranges in external workbook with formula criteria

Need Help on Named Ranges in Formulas:
I have a second workbook ('TEST.xlsx') as the destination, referencing worksheet-scoped named ranges (in 12 columns X 75 rows) in the source workbook ('FLOW.xlsx'). I want to create a formula that will match a look-up value (a date entered into cell C3 in TEST that will return the matching named range IF there are 2 or more blank cells in that matched named range/column and the remaining named ranges/columns in that set of 12 columns with 2+ blank cells. The 12 separate columns in the source workbook ('FLOW') are named by month, year and location (ex., "jan_2019_class.1","feb_2019_class.1", etc.), the worksheet columns being C, H, M, R, W, AB, AG, AL, AQ, AV, BA, and BF. The rows are 80-155. I've only been able to make a simple working COUNTBLANK formula in my TEST workbook, ex.:
=COUNTBLANK('[FLOW.xlsx]Class_1-Chart'!jan_2019_class.1)
But NOT for successive columns (with different named ranges and the columns are non-sequential); and I can't figure out the functioning formula to combine with this to get the count AND data returned by criteria as described above. Please, no VBA/macros.
Thank you in advance for the help!
'TEST.xlsx' Screen Shot-RVSD
FLOW.xlsx- sample screenshot
There are many approaches but I personally prefer the use of helper rows/columns/cells and named ranges.
In my demonstration I used two class attendant schedule in two different year from January to June as shown below (they are sitting in Column C to M in my example):
As shown above, I have added two helper rows on top of each schedule. The first helper row is used to find out if there is 2 or more vacancies in each month, if so returns TRUE. I have given the name check.2019.class.1 and check.2021.class.5 for each of them.
The second helper row is simply showing the range name of each month such as jan_2019_class.1, feb_2019_class.2 etc. I have given the name NameRng.2019.class.1 and NameRng.2021.class.5 for each of them.
On the TEST sheet I have the following set up:
where the look up value in cell C3 is actually returned by a formula so it can be "dynamically" changed by the user. Please note in the following formula I used a name ClassNo which is essentially the value from cell B3.
=B2&"_"&B1&"_class."&ClassNo
I have also named cell C3 as Start_MthYrClass which will be used in my following formula.
The formula for looking up the first available month in 2019 if the start month is jan_2019_class.1 is:
=INDEX(NameRng.2019.class.1,MATCH(1,(TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,NameRng.2019.class.1,0))*Check.2019.class.1,0))
Please note it is an array formula so you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to first "filter" the range NameRng.2019.class.1 using this formula =TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,NameRng.2019.class.1,0), in which ROW($1:$11) represents {1;2;3;4;5;6;7;8;9;10;11} and TRANSPOSE will turn it into {1,2,3,4,5,6,7,8,9,10,11}. This range of numbers represents the column index in that specific range which is Column C to M (in your case it would be ROW($1:$56) as your data is in Column C to BF). Then I use MATCH to return the start column index of the look up month jan_2019_class.1, and it should return 1 as this month starts in the 1st place/column in the range NameRng.2019.class.1. So this is what I am actually comparing: {1,2,3,4,5,6,7,8,9,10,11}>=1, and it will return {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE}.
Then I multiply the above result with range Check.2019.class.1 which is essentially {FALSE,0,FALSE,0,TRUE,0,FALSE,0,TRUE,0,TRUE}. Then I will get {0,0,0,0,1,0,0,0,1,0,1}. FYI in Excel TRUE=1 and FALSE=0, so TRUE x FALSE = 0 while TRUE x TRUE = 1.
Lastly, I use MATCH to find out the position of the first 1 in the above result which is the 5th place/column, and then use INDEX to return the corresponding value from range NameRng.2019.class.1 which is mar_2019_class.1.
Here is a more universal formula which allows you enter it in the first cell C6 and drag it down to apply across board, if you have given names to the relevant cells and ranges in the same way as what I have demonstrated.
=IFERROR(INDEX(INDIRECT("NameRng."&B6&".class."&ClassNo),MATCH(1,(TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,INDIRECT("NameRng."&B6&".class."&ClassNo),0))*INDIRECT("Check."&B6&".class."&ClassNo),0)),"")
It is also an array formula so you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar.
It is essentially the same formula as the first one but I have added IFERROR to return a blank cell if there is no match, and I used INDIRECT to refer to the named ranges dynamically based on the year and class number chosen.
Now, if I change the look up criteria to mar_2021_class.5, here is an updated result:
Let me know if you have any questions. Cheers :)

Get the count of the first column in multiple sheets and display them in separate sheet

I'm dealing with Excel VLOOKUP and COUNTIF that gets the count of number of entries in first column of every sheet and display the results in separate sheet accordingly with the product
Example:
I have 4 sheets in excel (4 sheet related to 4 products say oldnavy/purell/BB/Macys)
Each sheet has multiple columns.
Im looking to get just get the count of number of rows in first column for all 4 sheets and place in fift sheet with product name in each row and count of it
Tried using VLOOKUP and COUNTIF
Any help would be greatly appreciated
If you're trying to dynamically reference worksheets, you need to use INDIRECT().
If, in Sheet5 you have your worksheet names "oldnavy/purell/BB/Macys" in A1:A4 respectively, then in cell B1 you could put
=COUNTA(INDIRECT("'" & A1 & "'!A:A"))
And drag it down. COUNTA counts all non-blank cells in a range.
If I understand correctly, do this:
=COUNTIF(Sheet1!A:A,"<>")
I believe you understand COUNTIF()
Condition "<>" basically means 'not equal to empty/nothing', so 'count all that is not empty'
Hope that helps

VLOOKUP on all sheets

I have a "Master" sheet with part numbers in column A and locations in column B. I have approx 200 sheets with just part numbers in column A. How can I apply VLOOKUP to all sheets so every part number on every sheet will have my location in column B? It will take forever to do it manually. Thanks
Here is one way to achieve a lookup of data from the Master Sheet, assuming the starting cell containing your lookup value is A2. This also assumes that all sheets are in the same workbook:
=VLOOKUP(A2,Master!$A$2:$B$11,2)
An explanation of what each argument does from left to right:
A2 - cell containing lookup value in one of the 200 sheets. (This can be any cell which contains a lookup value).
Master is the name of the sheet which contains the data to look up.
$A$2 is the top left cell for the table data to look up in the Master sheet, we want to use $ sign because the lookup table top left cell should be fixed.
$B$11 is the bottom right cell for the table to look up in the Master sheet, we want to use $ sign because the lookup table bottom right cell should be fixed.
2, this is the column index which includes value you want returned for a successful look up. The column index starts at 1 and increases to the right, The column at index 1 contains the lookup values. In your scenario, index 1 is Column A and specifying an index of 2 will index column B
To deal with blank cells or cells which are not found in the table you can extend this formula like so:
=IF(ISNA(VLOOKUP(A2,Master!$A$2:$B$11,2)),"",VLOOKUP(A2,Master!$A$2:$B$11,2))
This formula will do the lookup, if it does not find the value it is looking for it will leave the cell blank, otherwise it populates the cell with the found data.
You can now copy and paste to cell A2 (or replace A2 with starting cell) and then drag the formula down the column to the last cell that requires VLOOKUP from the data table in the Master sheet. For every row X, it will update the lookup return data for the corresponding lookup value.
You will need to copy the formula then drag it to fill the entire B column for each 200 sheets which is a bit tedious. An alternative is to write a macro which loops over each sheet in the workbook and populates the corresponding column with the result of the lookup from the Master sheet.
VLOOKUP works when the lookup value is in some column X and the value to return, the data, is to the right of X.
If the data to be returned is to the left of the lookup value, you must use a combination of MATCH and INDEX which is slightly more complicated.
To lookup data in a different workbook, you will need to create a link between the two workbooks, this article explains how to do so.
Think about changing all your data to a single sheet. You may try this home made function:
Function AllSheetVLookup(ByVal lookup_value, ByVal search_col As Long, ByVal return_col As Long, Optional book_rng As Range)
Dim ws As Worksheet, r As Long
On Error Resume Next
For Each ws In IIf(book_rng Is Nothing, Application.Caller, book_rng).Worksheet.Parent.Worksheets
r = Application.WorksheetFunction.Match(lookup_value, ws.Columns(search_col), 0)
If r Then AllSheetVLookup = ws.Cells(r, return_col): Exit Function
Next
AllSheetVLookup = CVErr(2042) 'Not found, #N/A! returned
End Function
lookup_value - value to search, has in VLOOKUP;
search_col - column number in worksheets where to search for value
return_col - column number to return value from matched with match
book_rng - optional. Cell in another book if another book is to be searched. If ommited, book where function is called is used.
Example:
=AllSheetVLookup("part_number", 1, 2)
Will search for value "part_number" in column A (1st) from all worksheets of current book, and return value of column B (2nd).

Resources