How do you automatically copy a formula across a row if the header contains text? - arrays

I have a Google Sheet that transposes a list of items as the headers of the sheet. This list changes frequently +/- which means that the number of column headers (row 2) change frequently. On the first row (under the header) I have a formula that populates the column contents based on the header name. How do I get my formula to only copy to ALL the columns that have a header name and not to the ones that are empty.
Note the empty columns need to be there.

try:
=ARRAYFORMULA(IF(2:2="",,TRANSPOSE(MMULT(TRANSPOSE(IF(A3:3500<>"", 1, 0)),
ROW(3:3500)^0))&" Results"))

Related

I have code that will remove a row when a box is checked but I need to ignore the first row of column headers

I have the following code that moves a row to another tab in my sheet but I need the code to ignore the first row with the column headers. Right now If I put a column header in field A1, it moves that row to the archive sheet as well. I have tried changing the 1 to a 2 in the getRange but still does it. Any help?
I continue to have problems posting the code. Not sure what is wrong.

How can I keep references to changing spreadsheet constant?

I have 2 columns in a sheet that are referencing another dynamic sheet which has new rows added at the top all the time.
I want column A to be a copy of column A in Sheet1, so this works to put in cell A1:
={Sheet1!A:A}
However, I want column B to a formula applied to every row in column B of Sheet1. Problem is, when I put in a a formula, e.g.
=formula(B1)
then it changes to
=formula(B30)
when 29 new rows added
I want it to stay as B1, but it won't. If I use an absolute reference $B$1 then I can't copy the formula down the column.
Any wizards out there to help me out?
If you want to get the matching row from a column of another worksheet, then use INDEX and ROW, like so:
=FORMULA(INDEX(Sheet1!$B:$B, ROW(), 1))
This will always return the value in Column B of Sheet1, on the same Row as the formula is in on Sheet2 - even if you insert rows at the top of Sheet1
You can do "partially absolute reference" (I don't know the correct way of saying this).
You can lock only the column so would be =$A1 which means that it will never change the column but when you drag down the formula, it will change to =$A2, =$A3...
Or you can lock only the row typing =A$1 This way it will be locked on the row only.
You can do this also by pressing F4 several times: 1 time will lock both, the 2nd time will lock the row only, the 3rd time the column only and the 4th time will delete the locking.
the proper way would be to use INDIRECT like:
=INDIRECT("Sheet1!B1:B")

How to count unique occurrences with criteria in excel

I'm using the below array formula to count the unique occurrences of text in column C using the agent name in column G as the reference. This is giving me multiple issues.
=SUM( --(FREQUENCY(IF(G3:G100000 = J5,MATCH(C3:C100000,C3:C100000,0)),ROW(C3:C100000) - ROW(C3) + 1) > 0))
Depending on the data set I'm using multiple agents will return a #N/A result and I can't figure out why.
Each dataset I'm using is 20k to 30k lines, so the formulas take a long time to process.
Any ideas how I could do this faster or better? Also any ideas why some agents get bad returns?
I am assuming that you are looking for the number of unique combinations of columns C and G.
Create a pivot table and check the box to add this data to the data model.
Drag both column headers to the Rows section, also drag one (of those same two) into the the values section.
click on the the field in the values section > value field settings > summarize values by > choose Distinct Count. This removes all duplicates.
Click the Row Labels filter and uncheck the blanks.
You can drop in new data then right-click on the pivot and refresh to see the new results. See the image.

Get column header of last non-empty cell in unknown row

I have a table in a sheet called "DATA" with the following headers:
Country, Code, Series, 2000, 2001, 2002, 2003, 2004, 2005, 2006.
In each row I have data for all columns always, except for years. Some rows have data for some years only, others all years.
In sheet "DATA AVAILABILITY" I want to build a formula which returns the most recent year for which there is available information in sheet "DATA", given a certain country and code. The relevant country and codes are in cells E2 and A3 of "DATA AVAILABILITY". Let's say, for argument's sake, that these are Country: Angola; Code: 3.
I have first built an array MATCH formula with two criteria:
={MATCH(1,('DATA AVAILABILITY'!E$2=Data!$B$1:$B$104701)*('DATA AVAILABILITY'!$A3=Data!$D$1:$D$104701),0)}
This has successfully given me the row in "DATA" in which there is information for Angola and code 3, which is row 1776.
Now I would like to get the header for the last non-empty cell of row 1776 in sheet "DATA". For this, I started by building a formula that would give me the column number of that cell:
=LOOKUP(2,1/(Data!1776:1776<>""),COLUMN(Data!1776:1776))
It successfully returned the number 53 which, after verifying on sheet "Data" is the correct number. I then added to the formula so that it would return the header, i.e., the year, instead of the column number:
=INDEX(Data!$A$1:$BE$104701,1,LOOKUP(2,1/(Data!1776:1776<>""),COLUMN(Data!1776:1776)))
Finally, I would like to combine both formulas (the MATCH and the INDEX formulas) so that the final result would be returned with one formula only. However, when I try to do it, something goes wrong and an error comes up - I am not even able to enter the formula. When I click ENTER, Excel returns an error that says there is a problem with the formula. what I have tried to do is to replace, in the LOOKUP within the INDEX, "Data!1776:1776" for the array MATCH formula that returns the row in which the information is - in my example, row 1776. The final formula which is not working is as follows:
=INDEX(Data!$A$1:$BE$104701,1,LOOKUP(2,1/(MATCH(1,('DATA AVAILABILITY'!E$2=Data!$B$1:$B$104701)*('DATA AVAILABILITY'!$A3=Data!$D$1:$D$104701)<>""),COLUMN(MATCH(1,('DATA AVAILABILITY'!E$2=Data!$B$1:$B$104701)*('DATA AVAILABILITY'!$A3=Data!$D$1:$D$104701))))
What may I be doing wrong?
Thank you
Hard to tell what is going on without at least some sample data (as a table or linked workbook -- NOT as a screenshot), and I would do it a bit differently.
You can simplify your formula to get the Header of the column that contains the last data in row 1776:
=LOOKUP(2,1/(Data!1776:1776<>""),Data!$1:$1)
To return the column number:
=LOOKUP(2,1/(Data!1776:1776<>""),COLUMN(Data!$1:$1))
To return the Appropriate Row Number (enter with CSE):
=MAX(($E$2=Data!$B$1:$B$104701)*(A3=Data!$D$1:$D$104701)*ROW($A$1:$A$104701))
To return the last filled in value, in the row that matches Country and Code, we make use of the fact that using 0 for the column number in the INDEX function returns all the columns in the designated row:
=LOOKUP(2,1/(INDEX(Data!$B$1:$BE$104701,MAX(($E$2=Data!$B$1:$B$104701)*(A3=Data!$D$1:$D$104701)*ROW($A$1:$A$104701)),0)<>""),INDEX(Data!$B$1:$BE$104701,MAX(($E$2=Data!$B$1:$BE$104701)*(A3=Data!$D$1:$D$104701)*ROW($A$1:$A$104701)),0))
entered with CSE.

Get corresponding value from other sheet in excel (only returning first column)

I currently have the following formula, where the intention is to search one sheet for names, then pull the job title from another sheet with the same layout. However, it keeps only returning job titles from C column, and I to some extent know why, but I have no idea how to get the index, and in turn cell address call, to return matches with the correct column value.
Essentially the ActualVolunteerSchedule sheet has names, the TaskingSchedule has jobs in the time slots.
In EmailPrep sheet I am combining the time marker from column A with the job title from inside the table based on finding a matching name from row 1 in the email prep sheet.
So given a range say B:H on sheet1 - find all cells containing NAME, then grab cell contents from sheet2 with the same address. NAME found at sheet1!$C$3 then return value of sheet2!$C$3
INDIRECT("TaskingSchedule"&"!"&RIGHT(CELL("address",INDEX(ActualVolunteerSchedule!$C$1:$H$74,
SMALL(IF(ActualVolunteerSchedule!$C$1:$H$74=B$1,ROW(ActualVolunteerSchedule!$C$1:$H$74)),ROWS(A$3:A3)))),4))
Actual File
Google Sheet

Resources