Get row index of all non-empty cells in a column in Google Sheet - google-sheets

I want to create a function that gives me a list of all the nonempty row indices in the example shown below (i.e., 3,4,6,7,8,9,12,15).
After that, I want to select, for example, the third number in this list (i.e., 6).
I can't figure out how to make it happen (I am still fairly new to Google Sheet formulas), so very thankful for your help!
Sheet example:

It is not quite clear to me what you need.
I think you are asking for the # of the 1st row below 3rd empty row
=SMALL(ArrayFormula(IF(B1:B="",,ROW(B1:B))),3)
You can also find the # of empty rows using:
=ArrayFormula(IF(B1:B<>"",,ROW(B1:B)))
Change it to the following to get a list of non-empty rows
=ArrayFormula(IF(B1:B="",,ROW(B1:B)))
In any case, I have also included a couple more useful formulas
the # of the 3rd empty row
=SMALL(ArrayFormula(IF(B1:B<>"",,ROW(B1:B))),3)
and finally, the row content of the above formula
=INDEX(B1:B,SMALL(ArrayFormula(IF(B1:B="",,ROW(B1:B))),3),1)
(if still facing issues, do let us know)

Related

Output array formula, ignoring cells in output area that already contain data

I'm trying to work on a Google Sheet and make it as user friendly as possible, so when I'm not around others can't screw it up. I have previously copied the formula down the column, but I'm trying to do it in an array formula, that is in the header of the column so people don't need to copy the formula to other cells.
The formula is simply a VLOOKUP, comparing a cell to the left with the code, and retrieving the title and other information later. (I've had this working happily via copying the formula down the column.)
VLOOKUP($F$2:F, 'Lessons NEW'!$E$2:$F,2,false)
My problem comes when trying to do this using an array formula in the header. This also works properly, but doesn't allow me to do somethings needed.
={"Title";
ARRAYFORMULA(
IF($F2:$F<>"",
VLOOKUP($F$2:F, 'Lessons NEW'!$E$2:$F,2,false),
)
)}
Again this works happily.
HOWEVER. my issue is that on some rows I need to manually enter some info.
What I want to happen, is rows in the column that have data, in the array formula's destination to get skipped over and simply ignored during the array formula's output and end up containing what's been manually entered in them. (Some rows in the column will just be random manual entry stuff)
I've tried doing this via checking if there is a code in the cell to the left, and try to make it skip if so, or check if the destination cell has contents already and skip if so. but it seems that if I have anything in the output area of the array formula, it breaks it completely.
Does anyone have any suggestions of how I can accomplish this? Thanks!
Unfortunately there's no direct solution within ARRAYFORMULA. If you can, and ideally there are no in between rows added, you can add a column to the left to be hidden, and contain the formula adapted:
={"",VLOOKUP($F2, 'Lessons NEW'!$E$2:$F,2,false)}
Without ARRAYFORMULA it will be able to expand at any row that doesn't have a handwritten value. You may also protect that whole hidden column (that will mean also that no in between rows will be added by noon authorised people, may be also useful for you)
UPDATE
Sample script for copying the formula. Adapt the ranges and name of the sheet:
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
SpreadsheetApp.getUi().createMenu("Custom")
.addItem("Copy Formula","copyformula")
.addToUi()
copyformula()
}
function copyformula(){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sh = ss.getSheetByName("Sheet3")
var range = sh.getRange("D1")
range.copyTo(sh.getRange("D2:D"))
}
what you describe contradicts the intended usage of arrayformula. arrayformula is designed to roll out and for that, it needs an empty space. any manual input in that empty space will render the arrayformula out of the game. there are only two solutions for your issue:
not use arrayformula but VLOOKUP formula in every cell
use a script that will inject the formula only if there is no manual input
and one more hybrid solution - have your arrayformula in one column and your manual input in the next column, and then have 3rd column that will gather the data like if manual column is empty output vlookup otherwise output manual input

Combining Arrayformula with textjoin to eliminate delimiters

I am trying to use an arrayformula to join a string of cells in the same row as per picuture. This formula needs to automatically copy down to any new rows that are added. The formula I have so far seems to be the only one that returns at least something. I have googled and tried all sorts of join, textjoin to eliminate delimiters when a cell is empty but I keep getting all sorts of errors.
Also, note in column L I only want part of the cell, the city name, not state and zip code, which is why I added the Left function.
I would also like a header in row D1 "Summary".
Also, another problem I am having with the Arrayformula, is that any new rows that are submitted by my script, get pasted way down the bottom of the sheet, skipping blank rows. I think it sees the array formula as part of the last row even though those rows are blank. The only workaround I have so far is to delete all empty rows after my table, so I have the little [add 1000 more rows at bottom] after my last data row. But this then effects the filter range. The filter range does not seem to update automatically when new rows added. Maybe I need to address each of these issues as a new question in Stakoverflow?
Jobs Database
Delete everything from 'Jobs Database'!D:D (you can always undo it if you aren't happy with the formulas proposed). Then place one of the following two formulas in D1, though I recommend the second of the two.
The following formula will produce results in keeping with what you showed in your post and what is currently in the sheet (though my formula creates a cleaner result, because it addresses more potential issues than your original formula):
=ArrayFormula(FILTER(IF(ROW(A:A)=1,"Summary",B:B&IF(C:C="",," - "&REGEXREPLACE(TO_TEXT(C:C),"^-",""))&" - "&IF(H:H="",,H:H&" x ")&G:G&IF(I:I="",," - "&I:I)&" - "&IF(J:J="",,REGEXREPLACE(J:J,",$","")&" - ")&IFERROR(REGEXEXTRACT(L:L,"(.+)[\s\w]{8}")&" - ")&"ID: "&A:A),A:A<>""))
This formula is written to accommodate the fact that you've got column-level sorting in place. The FILTER clause surrounding everything inside also assures that the results only run as far down as you have data in Column A. This should eliminate the issue you were having with new rows being added after blanks.
I recommend the layout produced by this second formula, however:
=ArrayFormula(FILTER(IF(ROW(A:A)=1,"Summary",B:B&IF(C:C="",,CHAR(10)&TO_TEXT(C:C))&CHAR(10)&IF(H:H="",,H:H&" x ")&G:G&IF(I:I="",,CHAR(10)&I:I)&CHAR(10)&IF(J:J="",,REGEXREPLACE(J:J,",$","")&CHAR(10))&IFERROR(REGEXEXTRACT(L:L,"(.+)[\s\w]{8}")&CHAR(10))&"ID: "&A:A),A:A<>""))
In my opinion, the use of line breaks between information is cleaner and therefore easier to read.
Both formula options would require selecting all rows, right clicking, choosing "Resize rows" and selecting "Fit to data" for full viewing.
I have added two sheet ("Erik Help 1" and "Erik Help 2") with each of the above formulas in place, respectively).

I need to compare values between two sheets to find matching items

I need to compare two different sheets to find matching values between them.
In the first sheet, I have a list of order numbers and in the second one, I have a list that needs dispatching. Therefore, without scrolling through the sheet manually for the 1000+, I'd like to use a formula or conditional formatting in order to flag the values that are the same (or all of the different values) so I can simply copy and paste this into another sheet.
I have shared a link to a google sheet below if someone could help with this that would be very much appreciated.
Edit: The second sheet (on the google document) is the list of all orders and the first are the ones to be dispatched. I need to know which one's from the second sheet are missing from the first.
https://docs.google.com/spreadsheets/d/18vSBu9GzxK1UMCE2RrDyNSH6yi-FzTvuABsVw9r172Y/edit?usp=sharing
In second sheet in column B you could do:
=COUNTIF(Sheet1!A:A,A2)
IF the formula returns 0, it means that id number is not in your first sheet.

How to delete blank cells of the column in Google Sheets?

I am trying to get rid of the blank cells of the column in my sheet. I get some data from my colleagues via Google Form, and I have made some subcategory questions for them. So they get to select one of the five given choices. When I export the data to the sheet, it appears somewhat like below (linked):
https://docs.google.com/spreadsheets/d/1DBrFFNst0nhZAtxHejsrbNGkMxvcbOuie47era0Hl8c/edit?usp=sharing
Because the users can select one choice, out of five given choices four other cells must be left empty. Here's where I'm struggling with:
I have used filter function to get rid of the blank cells, but then it is restricted to only set the range either single row or column. So I end up with what you would see in my sample worksheet.
I've tried arrayformula and query as well, but I couldn't figure out a way out of this.
Any help would be appreciated.
=ARRAYFORMULA({B1:G7, {"subcategory"; TRIM(TRANSPOSE(QUERY(TRANSPOSE(H2:L7),,999^99)))}})

Google Spreadsheet & ArrayFormula - auto-adding formulas

I'm having problems with something that is likey very simple to correct. I have a form that submits data to a Google Spreadsheet, simply a date, name and score. On a separate sheet I am going to have a leaderboard which shows all submissions ranked by highest score (for simplicity in the example in the link below, I just have the leaderboard showing up on the right of the same sheet). I have it sorting the data fine, but I'm struggling with getting the 'rank' value to display. As shown for the first 3 rows (G2, G3, G4) I know what the formula is to display the 'rank' value...but what I'm struggling with is how to get that value to show without having to have that formula in each cell. Since the data will be coming from a form, there will obviously be new rows added regularly which means the leaderboard will automatically get adjusted and I want all of the rows to display the rank #. From what I have read, ArrayFormula should allow this to work, but even with looking at examples I can't figure out how to get it to work with my formula.
I know I could just highlight the entire 'G' column and paste in the formula, and hope it adds it to enough rows...but then it displays 'N/A' for all of the rows which don't currenlty have any data.
Hoping its just a simple solution that I'm being dumb and missing...any help would be greatly appreciated. The link to an example is below. To summarize, for all rows that have content in column H and I, the G cell for that row should show the rank value automatically.
https://docs.google.com/spreadsheets/d/1pCIJQi5g2scOtB6o2PgVVb-0azzhupEOPjiL0RMM57A/edit?usp=sharing
Thank you!
=ARRAYFORMULA(RANK(INDIRECT("I2:I"&COUNTA(H:H)),$I$2:I,0))
This will automatically rank and sort, for all values, including additional ones that are added. You only need to enter it into G2, and it will dynamically fill in the rest for you.
You can use
IFERROR(RANK(...),"")
and drag it to all rows - this will leave blank cells instead of #N/As. I'm sure there are other ways but that seems like the easiest one to me.

Resources