How to find the last row of an array with a non-empty cell?
up vote
0
down vote
favorite
//Sample sheet here
Hi,
I am using formulas to calculate an array N:R. Once calculated, I want to determine the last row of the array with a non-empty cell (the empty cells are not blank).
What I can do so far:
Return the last non-empty cell of a column
=INDEX(FILTER(O:O,O:O<>""), ROWS(FILTER(O:O,O:O<>"")))
or the row of the filter selection (in my case 25 in the filter selection vs 38 in the sheet)
=ROWS(FILTER(O:O,O:O<>""))
What I haven't figured out is how to:
- Do this search for the whole array and not just one row at a time
- Return the row of the last non-empty cell in the array
Cheers
google-sheets
add a comment |
up vote
0
down vote
favorite
//Sample sheet here
Hi,
I am using formulas to calculate an array N:R. Once calculated, I want to determine the last row of the array with a non-empty cell (the empty cells are not blank).
What I can do so far:
Return the last non-empty cell of a column
=INDEX(FILTER(O:O,O:O<>""), ROWS(FILTER(O:O,O:O<>"")))
or the row of the filter selection (in my case 25 in the filter selection vs 38 in the sheet)
=ROWS(FILTER(O:O,O:O<>""))
What I haven't figured out is how to:
- Do this search for the whole array and not just one row at a time
- Return the row of the last non-empty cell in the array
Cheers
google-sheets
I'm finding it hard to understand what you want to achieve here. It looks to me that you figured out not to "Return the last non-empty cell of a row" but rather "… of a column". Do you want to search for the last row of a multi-column array where there are non-empty cells in a) all columns of this row b) any column of this row? Also you indicate in your example that the last non-zero item of the array is row 35, whereas I can see it as row 38. Confusing. Perhaps a simpler example sheet would help.
– ttarchala
15 hours ago
Yes, you are completely right (just edited it, the first formula I give does indeed return the last non-empty cell of a column). What I am trying to accomplish is return the row number of the last non-empty cell in an multicolumn array. In the sheet it should be 38 as you mentioned (also highlighted it in the example a bit better)
– jlo
10 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
//Sample sheet here
Hi,
I am using formulas to calculate an array N:R. Once calculated, I want to determine the last row of the array with a non-empty cell (the empty cells are not blank).
What I can do so far:
Return the last non-empty cell of a column
=INDEX(FILTER(O:O,O:O<>""), ROWS(FILTER(O:O,O:O<>"")))
or the row of the filter selection (in my case 25 in the filter selection vs 38 in the sheet)
=ROWS(FILTER(O:O,O:O<>""))
What I haven't figured out is how to:
- Do this search for the whole array and not just one row at a time
- Return the row of the last non-empty cell in the array
Cheers
google-sheets
//Sample sheet here
Hi,
I am using formulas to calculate an array N:R. Once calculated, I want to determine the last row of the array with a non-empty cell (the empty cells are not blank).
What I can do so far:
Return the last non-empty cell of a column
=INDEX(FILTER(O:O,O:O<>""), ROWS(FILTER(O:O,O:O<>"")))
or the row of the filter selection (in my case 25 in the filter selection vs 38 in the sheet)
=ROWS(FILTER(O:O,O:O<>""))
What I haven't figured out is how to:
- Do this search for the whole array and not just one row at a time
- Return the row of the last non-empty cell in the array
Cheers
google-sheets
google-sheets
edited 10 hours ago
asked yesterday
jlo
603169
603169
I'm finding it hard to understand what you want to achieve here. It looks to me that you figured out not to "Return the last non-empty cell of a row" but rather "… of a column". Do you want to search for the last row of a multi-column array where there are non-empty cells in a) all columns of this row b) any column of this row? Also you indicate in your example that the last non-zero item of the array is row 35, whereas I can see it as row 38. Confusing. Perhaps a simpler example sheet would help.
– ttarchala
15 hours ago
Yes, you are completely right (just edited it, the first formula I give does indeed return the last non-empty cell of a column). What I am trying to accomplish is return the row number of the last non-empty cell in an multicolumn array. In the sheet it should be 38 as you mentioned (also highlighted it in the example a bit better)
– jlo
10 hours ago
add a comment |
I'm finding it hard to understand what you want to achieve here. It looks to me that you figured out not to "Return the last non-empty cell of a row" but rather "… of a column". Do you want to search for the last row of a multi-column array where there are non-empty cells in a) all columns of this row b) any column of this row? Also you indicate in your example that the last non-zero item of the array is row 35, whereas I can see it as row 38. Confusing. Perhaps a simpler example sheet would help.
– ttarchala
15 hours ago
Yes, you are completely right (just edited it, the first formula I give does indeed return the last non-empty cell of a column). What I am trying to accomplish is return the row number of the last non-empty cell in an multicolumn array. In the sheet it should be 38 as you mentioned (also highlighted it in the example a bit better)
– jlo
10 hours ago
I'm finding it hard to understand what you want to achieve here. It looks to me that you figured out not to "Return the last non-empty cell of a row" but rather "… of a column". Do you want to search for the last row of a multi-column array where there are non-empty cells in a) all columns of this row b) any column of this row? Also you indicate in your example that the last non-zero item of the array is row 35, whereas I can see it as row 38. Confusing. Perhaps a simpler example sheet would help.
– ttarchala
15 hours ago
I'm finding it hard to understand what you want to achieve here. It looks to me that you figured out not to "Return the last non-empty cell of a row" but rather "… of a column". Do you want to search for the last row of a multi-column array where there are non-empty cells in a) all columns of this row b) any column of this row? Also you indicate in your example that the last non-zero item of the array is row 35, whereas I can see it as row 38. Confusing. Perhaps a simpler example sheet would help.
– ttarchala
15 hours ago
Yes, you are completely right (just edited it, the first formula I give does indeed return the last non-empty cell of a column). What I am trying to accomplish is return the row number of the last non-empty cell in an multicolumn array. In the sheet it should be 38 as you mentioned (also highlighted it in the example a bit better)
– jlo
10 hours ago
Yes, you are completely right (just edited it, the first formula I give does indeed return the last non-empty cell of a column). What I am trying to accomplish is return the row number of the last non-empty cell in an multicolumn array. In the sheet it should be 38 as you mentioned (also highlighted it in the example a bit better)
– jlo
10 hours ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
This custom function will do it. Sometimes scripts are way easier than some of the bizarre formulas that arise (IMHO). It just loops through the data row by row and notes the row number if it finds data ie cell.value() != ""
function findHighestNonEmptyRow(){
var sheet = SpreadsheetApp.getActive();
var range = sheet.getRange("N:D");
var valuesRC = range.getValues();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
var highestNonEmptyRow = 0;
for (var row = 0; row < numRows; row++) {
for (var col = 0; col < numCols; col++) {
if (valuesRC[row][col] != ""){
highestNonEmptyRow = row+1; // +1 to offset loop variable
}
}
}
Logger.log(highestNonEmptyRow);
return highestNonEmptyRow;
}
Log show correct value of 38
. You can delete the Logger.log(highestNonEmptyRow)
; line when you have tested.
I put the formula in W44
in your test sheet....
add a comment |
up vote
0
down vote
For a formulaic approach, you can try
=max(Arrayformula(filter(row(N2:N), MMULT(N(N2:R<>""), transpose(column(N2:R2)^0))>0)))
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This custom function will do it. Sometimes scripts are way easier than some of the bizarre formulas that arise (IMHO). It just loops through the data row by row and notes the row number if it finds data ie cell.value() != ""
function findHighestNonEmptyRow(){
var sheet = SpreadsheetApp.getActive();
var range = sheet.getRange("N:D");
var valuesRC = range.getValues();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
var highestNonEmptyRow = 0;
for (var row = 0; row < numRows; row++) {
for (var col = 0; col < numCols; col++) {
if (valuesRC[row][col] != ""){
highestNonEmptyRow = row+1; // +1 to offset loop variable
}
}
}
Logger.log(highestNonEmptyRow);
return highestNonEmptyRow;
}
Log show correct value of 38
. You can delete the Logger.log(highestNonEmptyRow)
; line when you have tested.
I put the formula in W44
in your test sheet....
add a comment |
up vote
0
down vote
This custom function will do it. Sometimes scripts are way easier than some of the bizarre formulas that arise (IMHO). It just loops through the data row by row and notes the row number if it finds data ie cell.value() != ""
function findHighestNonEmptyRow(){
var sheet = SpreadsheetApp.getActive();
var range = sheet.getRange("N:D");
var valuesRC = range.getValues();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
var highestNonEmptyRow = 0;
for (var row = 0; row < numRows; row++) {
for (var col = 0; col < numCols; col++) {
if (valuesRC[row][col] != ""){
highestNonEmptyRow = row+1; // +1 to offset loop variable
}
}
}
Logger.log(highestNonEmptyRow);
return highestNonEmptyRow;
}
Log show correct value of 38
. You can delete the Logger.log(highestNonEmptyRow)
; line when you have tested.
I put the formula in W44
in your test sheet....
add a comment |
up vote
0
down vote
up vote
0
down vote
This custom function will do it. Sometimes scripts are way easier than some of the bizarre formulas that arise (IMHO). It just loops through the data row by row and notes the row number if it finds data ie cell.value() != ""
function findHighestNonEmptyRow(){
var sheet = SpreadsheetApp.getActive();
var range = sheet.getRange("N:D");
var valuesRC = range.getValues();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
var highestNonEmptyRow = 0;
for (var row = 0; row < numRows; row++) {
for (var col = 0; col < numCols; col++) {
if (valuesRC[row][col] != ""){
highestNonEmptyRow = row+1; // +1 to offset loop variable
}
}
}
Logger.log(highestNonEmptyRow);
return highestNonEmptyRow;
}
Log show correct value of 38
. You can delete the Logger.log(highestNonEmptyRow)
; line when you have tested.
I put the formula in W44
in your test sheet....
This custom function will do it. Sometimes scripts are way easier than some of the bizarre formulas that arise (IMHO). It just loops through the data row by row and notes the row number if it finds data ie cell.value() != ""
function findHighestNonEmptyRow(){
var sheet = SpreadsheetApp.getActive();
var range = sheet.getRange("N:D");
var valuesRC = range.getValues();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
var highestNonEmptyRow = 0;
for (var row = 0; row < numRows; row++) {
for (var col = 0; col < numCols; col++) {
if (valuesRC[row][col] != ""){
highestNonEmptyRow = row+1; // +1 to offset loop variable
}
}
}
Logger.log(highestNonEmptyRow);
return highestNonEmptyRow;
}
Log show correct value of 38
. You can delete the Logger.log(highestNonEmptyRow)
; line when you have tested.
I put the formula in W44
in your test sheet....
edited 5 hours ago
answered 7 hours ago
bcperth
1,9151513
1,9151513
add a comment |
add a comment |
up vote
0
down vote
For a formulaic approach, you can try
=max(Arrayformula(filter(row(N2:N), MMULT(N(N2:R<>""), transpose(column(N2:R2)^0))>0)))
add a comment |
up vote
0
down vote
For a formulaic approach, you can try
=max(Arrayformula(filter(row(N2:N), MMULT(N(N2:R<>""), transpose(column(N2:R2)^0))>0)))
add a comment |
up vote
0
down vote
up vote
0
down vote
For a formulaic approach, you can try
=max(Arrayformula(filter(row(N2:N), MMULT(N(N2:R<>""), transpose(column(N2:R2)^0))>0)))
For a formulaic approach, you can try
=max(Arrayformula(filter(row(N2:N), MMULT(N(N2:R<>""), transpose(column(N2:R2)^0))>0)))
answered 56 mins ago
JPV
9,98221425
9,98221425
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238533%2fhow-to-find-the-last-row-of-an-array-with-a-non-empty-cell%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I'm finding it hard to understand what you want to achieve here. It looks to me that you figured out not to "Return the last non-empty cell of a row" but rather "… of a column". Do you want to search for the last row of a multi-column array where there are non-empty cells in a) all columns of this row b) any column of this row? Also you indicate in your example that the last non-zero item of the array is row 35, whereas I can see it as row 38. Confusing. Perhaps a simpler example sheet would help.
– ttarchala
15 hours ago
Yes, you are completely right (just edited it, the first formula I give does indeed return the last non-empty cell of a column). What I am trying to accomplish is return the row number of the last non-empty cell in an multicolumn array. In the sheet it should be 38 as you mentioned (also highlighted it in the example a bit better)
– jlo
10 hours ago