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:




  1. Do this search for the whole array and not just one row at a time

  2. Return the row of the last non-empty cell in the array


Cheers










share|improve this question
























  • 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

















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:




  1. Do this search for the whole array and not just one row at a time

  2. Return the row of the last non-empty cell in the array


Cheers










share|improve this question
























  • 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















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:




  1. Do this search for the whole array and not just one row at a time

  2. Return the row of the last non-empty cell in the array


Cheers










share|improve this question















//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:




  1. Do this search for the whole array and not just one row at a time

  2. Return the row of the last non-empty cell in the array


Cheers







google-sheets






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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




















  • 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














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....






share|improve this answer






























    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)))





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      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
































      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....






      share|improve this answer



























        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....






        share|improve this answer

























          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....






          share|improve this answer














          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....







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 hours ago

























          answered 7 hours ago









          bcperth

          1,9151513




          1,9151513
























              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)))





              share|improve this answer

























                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)))





                share|improve this answer























                  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)))





                  share|improve this answer












                  For a formulaic approach, you can try



                  =max(Arrayformula(filter(row(N2:N), MMULT(N(N2:R<>""), transpose(column(N2:R2)^0))>0)))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 56 mins ago









                  JPV

                  9,98221425




                  9,98221425






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      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




















































































                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine