Currently, I have a summary excel tab in my workbook where I am hardcoding the sheetname to get a count from it as follows:
=COUNTIF('SheetName1'!$D:$D,E$2)
I have the sheet name in the adjacent cell as well.
I have been trying to figure out how to dynamically link it with the adjacent cell value:
Something like =COUNTIF('&B3&'!$D:$D,E$2)
Edit: Easier test sample is COUNTA instead of COUNTIF: =COUNTA('SheetName1'!$A:$A)-1
The problem is the same
You need INDIRECT() function-
=COUNTIF(INDIRECT(B3&"!D:D"),E2)
For above formula B3 contains sheetname and E2 contains criteria data.
Related
I have 15 Google Workbooks that import into 1 Workbook tab through an Importrange + Query combo function. The data is then queried and transformed across several other tabs, but the problem definitely begins on this tab.
Although I've manually forced a format change to "Number" in each workbook source AND in Columns CO:CQ (where the problematic data lands), all functions see the data as zero or null. Here is what happens when I set a random cell (CW33) equal to a cell in one of the trouble columns (CO33)
However, when I wrap the cell in an =sum(), the workbook returns "0":
I have no idea how to force the workbook to see the values in these rows as numbers without creating an entirely new column - does anyone have any ideas on how to fix it while preserving the column structure?
Thanks!
try:
=SUM(CO33*1)
for multiple cells it would be:
=ARRAYFORMULA(SUM(CO33:CO34*1))
or:
=SUMPRODUCT(CO33:CO34)
AFAIK, in Sheets, a Number formatted cell displays contents right-aligned and Plain-Text are left-aligned. The highlighted cell looks like a text cell.
Try changing the format of cell or column manually to 'Number' from the 'Format' tab.
I have a google sheet with formulas that go by the cell in the previous row (e.g. =IF(D12=FALSE,E11,E11+1). When I insert a new row, the formula doesn't copy into the new row.
I was looking to create a table like you could in excel so that you could write formulas like =[#[header]] and when you inserted a new row, this carried into the new row.
Does anyone know how you can either create an array formula for the two below formulas, or how to format as table so you can define the =[#[header]] functions?
Two formulas that could be written as array:
For my sheet this one is inserted in cell E2: =IF(D2=FALSE,E1,E1+1)
This formula is in F2: =IF(E1=E2,"",E2) - both continue for the entire column.
for first use:
=ARRAYFORMULA(IF(D2:D1000=FALSE, E1:E999, E1:E999+1))
and the second:
=ARRAYFORMULA(IF(E1:E999=E2:E1000,,E2:E1000))
if you want it with header then:
={"header title"; ARRAYFORMULA(IF(E1:E999=E2:E1000,,E2:E1000))}
Solution
For adding headers to your formulas using also ARRAYFORMULA just wrap the whole thing with {}. Note that in the second formula I have written E3 instead of E2 as E2 would have the title of its formula.
These are the formulas to be used in your specific scenario:
For E2 :
={"title 1";ARRAYFORMULA(IF(D2=FALSE, E1, E1+1))}
and for F2 :
={"title 2"; ARRAYFORMULA(IF(E1=E3, "", E3))}
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)
I have been working on querying multiple sheets of data and would like the text string from one of the cells to determine which sheet that row is querying but can not figure out how to do it. This is the most recent formula I have tried:
=QUERY(INDIRECT("B"&"2")&"!"&$2:$1000)
Cell B2 contains the name of the other sheet I am trying to query.
try:
=QUERY(INDIRECT(B2&"!2:1000"))
or:
=QUERY(INDIRECT(B2&"!B2:B1000"))
Previously I have an Excel VBA code that performs index & match formula from 1 sheet to another for an entire column in a table. Code example as below:
With Me.Range("table1[Description]")
.Formula = "=IFerror(INDEX(table2,MATCH(B4,table2[Asset No],0),2),"""")"
.Value = .Value
End With
Now I would like to add an array function into the sheet so I copied the formula and replace the old formula with array along with other modifications.
Sub refresh()
With Me.Range("table1[Last Service Date]")
.FormulaArray = "=LARGE(IF(table2[[#All],[Asset No]]=[#[Asset No]],table2[[#All],[Entry Date]]),2)"
.Value = .Value
End With
End Sub
But when I try to test the code, I keep getting the error message 400.
Anything I need to change in my code for array formulas?
What's the point of using Me in the code? Have you placed that code in the Sheet Module? I would suggest you to move this code on to the Standard Module like Module1 and replace the Me keyword with the proper sheet reference. Otherwise I hope you have a good reason to place that code into the sheet module.
Also you should place the Array Formula in the first cell of the table in the desired column and since the data is formatted as an Excel Table, the whole column will be filled with the formula automatically. If not, you can then use AutoFill property to fill down the formula down the rows.
Give this a try to see if that resolves your issue.
The answer assumes that the formula you are trying to place through VBA works well when you put it manually on the Sheet.
With Me.Range("table1[Last Service Date]").Cells(1)
.FormulaArray = "=LARGE(IF(table2[[#All],[Asset No]]=[#[Asset No]],table2[[#All],[Entry Date]]),2)"
.Value = .Value
End With
I am trying to make an excel template so that when a user copies data into the tab "Account Profile", the last row with contents in it is calculated and this value is used for formulas on other sheets. This formula calculates the last row with data:
=LOOKUP(2,1/('Account Data'!A:A<>""),ROW('Account Data'!A:A))
This works fine, the trouble comes when I try to use the result as a range reference: I want my formulas to iterate from row 2 --> row (value of LOOKUP)
=COUNTIF('Account Data'!$N$2:$N$991,A8)
The "991", I want that replaced with the result of the LOOKUP formula so that the range is always correct. I'm sure there's an easy way but I've tried for a while and can't figure out what the syntax should be.
Scott is right that you should just be using COUNTIF directly with a column reference. However, in case this is a contrived example or something, this is how you'd do it the way you described:
=COUNTIF(INDIRECT("'Account Data'!$N$2:$N$" & LOOKUP(2,1/('Account Data'!A:A<>""), ROW('Account Data'!A:A))), A8)
The important part to look at is INDIRECT("'Account Data'!$N$2:$N$" & LAST_ROW_NUMBER). The INDIRECT function is how you take a string of text and interpret it as a cell reference. The "Some text" & VARIABLE_NAME is how you build such a text string from variables: you use the & symbol to concatenate them.
COUNTIF is not an array formula and as such you can use full column references without detriment.
=COUNTIF('Account Data'!$N:$N,A8)
But if you really want a dynamic range then use INDEX/MATCH:
=COUNTIF('Account Data'!N2:INDEX('Account Data'!N:N,MATCH(1E+99,'Account Data'!A:A)),A8)
This will find the last cell in column A that has a number. If Column A is filled with text then replace 1E+99 with "ZZZ".
If you want to use LOOKUP then:
=COUNTIF('Account Data'!N2:INDEX('Account Data'!N:N,LOOKUP(2,1/('Account Data'!A:A<>""),ROW('Account Data'!A:A))),A8)