define range of all but last of occupied cells in a column - google-sheets

How can I define a range in Google Sheets to match all but the last occupied cell in a column? ie if column A is blank after A45, say, I want the range A1:A44. I have explored various constructs to find the row of the last occupied cell, eg
=ARRAYFORMULA(MAX(ROW(A:A)*(A:A<>"")))
How can I define the required range?

take:
=INDEX(INDIRECT("A1:A"&MAX(ROW(A:A)*(A:A<>"")))

Related

Google sheets; Compare data in 3 columns & rows and highlight cells if similar data

Right now I am tasked to compare similar data across 3 columns and its respective rows and then highlight them.
I was wondering whether if it is possible to format the spreadsheet so that the cells highlight on their own across their respective rows when similar data is entered into the cells.
I have attached an example in the link provided !
OK select the range you want to format then go to Format | Conditional format | Add new rule and choose the last option (Custom formula is...) under Format cells if...
Enter the following formula (adjusting range to how many rows and columns you have in your data)
=countifs($A$2:$A$18,$A2,$B$2:$B$18,$B2,$C$2:$C$18,$C2)>1
and choose the fill colour that you want.
The formula counts how many rows there are whose first three columns match the first three columns of the current row. If the result is greater than one, there is a duplicate and the current row should be formatted.

Working with hierarchical data in Google Sheets

If I have hierarchical data in a Google Sheet as in columns A and B in the example below, how can I write a formula that will fill the corresponding cells in column C with the product of the "parent" value in A1, and the "child" values in column B. That is, The formula in C8 for example, will search upward in column A until it finds the value 5 in A6, then multiplies it by 8, the value in B8.
Obviously I'm trying to avoid having to put the "parent" value in every row in column A.
After a fiddling around and jogging my memory on ArrayFormulas I figured out how to get the result I wanted. Here's the formula I'm using:
=ArrayFormula(index($B$2:$B2,MAX(IF(ISNUMBER($B$2:$B2),ROW($B$2:$B2)))-1,1))
(Note: Row 1 contains headings)
Edit: Explanation of how I arrived at this solution:
Ordinarily, IF(ISNUMBER(cell)), and ROW(cell) would return TRUE/FALSE, or a row number respectively. When used in an array formula and a range of cells as input instead, what you get is a list of TRUE/FALSE values, and row numbers evaluated for each cell in the input range. Wrap MAX around that and it will return the position in those two lists where IF(ISNUMBER()) is TRUE and the row number returned by ROW() is the highest, effectively searching from the bottom of the range.
The absolute reference for the first element in the range to be searched (in this case $B$2) keeps the range anchored to the same starting location when dragging the formula into other cells, while the lower bound of the range (in this case $B2) to be searched grows vertically.
Finally, the INDEX takes the input range, row number returned by the above (-1 row because of the header) and column position (1, since there is only one column) in order to return the desired value.
One way you could do this would be to associate each value in column B with a category or key that can be used to lookup the value for A in a separate table. This abstracts it somewhat, so you can change the values for the A column without having to have them in every row, but there's no empty cells.
i.e.
and lookup table:
In column C
= VLOOKUP($A1, <range for category lookup table>, 2, 0) * $B1
(And then this formula can be filled down)
More on VLOOKUP in Google Sheets here
Alternatively I suppose you could use a formula to find the last non-empty row in column A, or something along those lines, but this is more of a hack than a proper way to structure your data. Tables aren't really designed to be used in a hierarchical fashion like what you've shown. But they can easily represent hierarchical data using techniques like what I've suggested.

Google Sheets - How to highlight cells in a row that match values from other cells?

I have a row of values (say 1-10)
At the beginning of the rows I have 2 numbers generated from dates from other cells that represent week numbers. (eg, 3 and 9)
I want my row to highlight all the numbers from 1-10 that are between the values from the week number cells. (eg the cells with numbers 3,4,5,6,7,8 and 9 will automatically turn a colour (say green))
I've tried the conditional format, using the "between" values.
It doesn't work.
If I just type the numbers into the format box, it will work, but the problem is I need it to refer to the value in the cell NOT a number I type in, because there is a likelihood that the dates could change, which will affect the value shown in week number cell, so I need it to work automatically and not require me to go through every single row changing values for the formatting.
Is this even possible on sheets?
Thanks in advance, I am hoping I've just overlooked something simple.
Use a custom function for conditional formatting. For instance, if the columns you describe are in Row 2, this function will evaluate "TRUE" for numbers that are >= A2 and <= B2:
=AND(C2>=$A2,C2<=$B2)
Select the range of cells you wish to create a conditional format for; C2..L2, say. Open the conditional formatting dialog, and choose "Custom formula". Enter the formula above; note that itr refers to the top-left corner of the range you wish to apply the formula to - Sheets will automatically adjust it for the rest of the range, which is why it's important to use absolute references for the first two columns.

VlookUp: can I reference the range to a cell value

I am using Google Docs and unfortunately it does not have a GetPivotData function. As I add more categories and subcategories to my data, the Pivot Table data will be moving (column wise).
So I took the liberty to use formulas and find the Row and Column numbers for all my ranges, so regardless of any new data, my range will expand/contract/shift with the correct data.
Now all I have left is to use a VLOOKUP to feed the data for that specific subcategory. I have a cell that shows the value for my range.... my range is D7:S100... but like I said, if I add one more subcategory, then my range will be D7:T100 and my cell will reflect this change. I want to use this cell reference in my VLOOKUP so it can be dynamic in the range.
VLOOKUP(search_key, range, index, [is_sorted])
VLOOKUP(A1, cell reference, 2, 0)
Can the range ever be a cell reference so my vlookup's range be dynamic?
Use a Named Range. This is available in Google Spreadsheets from the Data menu.
Create a named range to represent your table of data.
Give it a name like myTable or whatever you want to call it, then you can use that Name in the formula:
=VLOOKUP("BOB",myTable,2)
If you need to expand the range, just go back in to the Named Range menu and edit the existing range.
I have not tested it yet but if this is like Excel, then you can even define a named range based on a formula (typically using the Offset, COUNTA, Index and some other functions to dynamically determine the size of the range). This is probably available to Google Spreadsheets but I have only done that in Excel.
Can the range ever be a cell reference so my vlookup's range be
dynamic?
There may be better ways of achieving what you need to do, but the short answer is yes - using INDIRECT.
B1: D7:T100
=VLOOKUP(A1,INDIRECT(B1),2,0)

How to find count of cells containing one or more specific words

I have a column with various text inputs. I'd like to count the number of cells that include either "word1" or "word2". So that if a single cell contains one or more of these it counts as one.
I've managed to make a formula that I think counts all occurrences of "word1" and "word2", but I'm only after the amount of cells containing one of them (or any number of them).
What is the formula for this?
You can use an array formula:
=ARRAYFORMULA(SUMPRODUCT(((ISNUMBER(SEARCH("word1",A1:A5))+ISNUMBER(SEARCH("word2",A1:A5)))>0)*1))
That formula was based on barry houdini's answer a while ago.
Just change the range as required.

Resources