Match Function with Google Sheets Apps Script -JavaScript IndexOf Method Tutorial - Part 16

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • Learn how to create Google Sheets Match function alternative using JavaScript in Apps Script.

КОМЕНТАРІ • 64

  • @davidduran2984
    @davidduran2984 4 роки тому

    This script was as short as it was useful. I was wondering about this for quite a while.

  • @bh-db2rp
    @bh-db2rp 5 років тому +2

    Hi, this is very interesting. However I ask for a range which is a column and I get a range of values in an array of an array.
    [[valrow1],[valrow2],[valrow3]] but I cannot find a way for the indexOf function to find my value.
    I used lookupvalue = "valrow3" or ["valrow3"] or "[valrow3]", none of them work.
    I am certainly not well versed in the syntax for array and I cannot find an answer.
    thanks for your help.

  • @vlth
    @vlth 4 роки тому

    Great vidéo !!
    (sorry for my English....)
    i'm wondering the same script for a row !!
    u give me the road !!! yessss

  • @trajanoroberto120
    @trajanoroberto120 4 роки тому

    another great video and great work
    congrats

  • @lazalazarevic6192
    @lazalazarevic6192 6 років тому

    Welcome back :) and thanx for another great video

  • @pan.sushant
    @pan.sushant 2 роки тому +1

    Trying to run the same code to find index of date but it never matches - checked both date formats are same and ran it through to check via if loop to verify both are same but doesnt work with while loop and index of it doesnt read it as same. Date format as shown in logger example - Sun Aug 29 14:30:00 GMT-4:00 2021

  • @rashidanwar7831
    @rashidanwar7831 5 років тому +1

    You are doing a great job. Keep it up and thank you.

  • @fantouch
    @fantouch 6 років тому +2

    Question, I want to use the same idea but instead of search in what column, I need what row. the problem is that the values are arrays inside of singles arrays. I want to find the name: "John" and the ...getRange(2, 2, lr, 1).getValues(); --> is [ [Carlos], [Mike], [John], [Tom]... ]
    I do not know why when we look by columns the values are simple as an array inside of and array, any tricks?
    for now I a using Match function in the sheet and then I get the value to the scrip.
    Regards
    CW

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  6 років тому +3

      getRange(2, 2, lr, 1).getValues().map(function(d){ return d[0] });

    • @fantouch
      @fantouch 6 років тому

      Thanks for the push, I will try it now and I will Google it to know what that do " funtion(d)".

    • @davidramos5510
      @davidramos5510 5 років тому

      getRange(2, 2, lr, 1).getValues().map(function(value) {return '' + value + ''});

  • @yehudagoldberg8577
    @yehudagoldberg8577 2 роки тому

    What would I do if I want to get a match that is not exact? Where the formula I would write would look like MATCH(value,array,-1)

  • @rakeshkumarrakee
    @rakeshkumarrakee 5 років тому

    thankz for this great video bro....

  • @leemorris4054
    @leemorris4054 3 роки тому

    Great video. I'm trying to modify this function to produce a row index but it doesn't show the range as CSV in the log, instead every cell data is in square brackets. Any ideas??

  • @chaitalikhona1617
    @chaitalikhona1617 2 роки тому

    Can we identify the columns if the labels are in different rows?

  • @DavidMarcadet
    @DavidMarcadet 5 років тому

    Great vidéo, thank you so much!

  • @walterelemino
    @walterelemino 4 роки тому +1

    I have a question, why my indexOf(SearchElement) is not showing when I try to put period after lookUpRangeValues? I copied all you code even the names are the same.

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 роки тому

      I don't know. So long as the code works, it doesn't matter.

    • @walterelemino
      @walterelemino 4 роки тому

      Learn Google Spreadsheets It is working now, I forgot the terminator at the top of my code. Thank you so much

  • @dewaynewest7756
    @dewaynewest7756 4 роки тому

    How would I compare 2 list from different sheets and return the index?

  • @ceeemmsss8149
    @ceeemmsss8149 5 років тому

    So where is part 17? Trying to add this to an existing script so that the formula remains static even if columns are added/removed. Right now my script is based on column numbers, so if a column is added or removed, I lose my formula

  • @abhiskek270
    @abhiskek270 6 років тому +1

    Hi LCS, Thanks for this video. Can you please help me out with an issue I am facing? My range is a single column. when i am cheking the logs, I am getting only the 1st element of the column.
    var arr2 = ss.getRange(2,1,r-1,1).getValues()[0];
    Logger.log(arr2);
    result = [Dog] (complete contents of the column -> Dog, Cat, Deer, Mouse, Dog)
    Thanks

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  6 років тому +3

      .getValues()[0] gets you the first row in the column.
      You can search your column to find Deer like this.
      var arr2 = ss.getRange(2,1,r-1,1).getValues();
      var deerPosition = arr2.findIndex(function(x){return x[0] == "Deer"}) + 1;

  • @markuswinter-cdps3008
    @markuswinter-cdps3008 4 роки тому

    Thanks for another great video. This is going to sound silly, but how much changes for completing this down a column instead of across rows? Does the array return change format?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 роки тому +1

      The answer is here ua-cam.com/video/S5TbN36E8Uw/v-deo.html

    • @markuswinter-cdps3008
      @markuswinter-cdps3008 4 роки тому

      @@ExcelGoogleSheets Thanks. I knew it was a silly question. Also, figured it out watching your Arrays & Map Method video. Awesome series. Thanks so much for doing them!!

    • @markuswinter-cdps3008
      @markuswinter-cdps3008 4 роки тому

      @@ExcelGoogleSheets Please pardon my lack of knowledge with this stuff. What I've been trying to do is match the text string of cell on one sheet(1) to a cell on another sheet (2). Have now been able to accomplish this via indexOf. Now, I'm trying use offset to uncheck a checkbox on the same row as my matched cell on sheet 2. Cannot, for the life of me, figure out how to use the indexOf position (happens to be 11) as a reference to do this. Do I need to convert the position to the actual value (text string) of the cell? What am I missing, or is there a completely different (and better) way of accomplishing this? Thanks in advance.

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 роки тому

      Do you want to do this with a script or it doesn't matter?

    • @markuswinter-cdps3008
      @markuswinter-cdps3008 4 роки тому

      @@ExcelGoogleSheets Script would be preferred, I guess, but not absolutely necessary.

  • @Rolroorlo
    @Rolroorlo 3 роки тому

    How can I use this for a single column instead of a single row

  • @phoenixempire8886
    @phoenixempire8886 4 роки тому +1

    🙏🏻

  • @danielramel6827
    @danielramel6827 5 років тому

    Hi! In the 11:00 minute the log returns the value 0.0.
    I can understand that why the lookupRangeValues.indexOf(lookupValue) returns something like false ( in this case 0.0), but than you add 1 to it , so why isn't it returns 1.0?
    Could you help me with that? Thank you for your answer in advance.

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  5 років тому

      Watch this video ua-cam.com/video/S5TbN36E8Uw/v-deo.html

  • @JAY-bo7tg
    @JAY-bo7tg Рік тому

    Dear sir how i reject duplicate entry from matching existing sheet value

  • @shaitaan2011
    @shaitaan2011 5 років тому

    Anybudy tells me which coding using in Google sheet i want to know all coding of spreadsheet where will i get it.

  • @Realmattvevo
    @Realmattvevo 3 роки тому

    Hey compare find with array and textFinder please!

  • @maxieearle4364
    @maxieearle4364 5 років тому

    This doesn't seem to work if numbers are in the array? it returns an array of arrays.

    • @maxieearle4364
      @maxieearle4364 5 років тому

      Another thing, how do I do this so that it updates when the spreadsheet updates

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  5 років тому +1

      convert array of arrays to regular array myArray = myArray.map(function(r){ return r[0] });

  • @giamar3026
    @giamar3026 2 роки тому

    Hi, i ask you for help! first do you have any video where i can learn how to buil an script to replace text in column when it match with ALL cell content. I can't do it as the text is added (and not replaced)when i run my script twice using range.createTextFinder("cat").replaceAllWith("cat & dog"), even using replace(old,new). Thank you.
    And Also i use a separate sheet where one column have old values and side column new values, my goal is the system loop these column and the sheet where values are, but got errors too:
    function FindAndReplace4() {
    var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    var lrow = ss.getLastRow();
    var rng = ss.getRange(2, 7, lrow - 1, 1);
    var data = rng.getValues();
    //where listed categories
    var ss1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('animalsToreplace');
    var lrow1 = ss1.getLastRow();
    var rng1 = ss1.getRange(2, 1, lrow1 - 1, 1);
    var data1 = rng1.getValues();
    for (var i=0; i < data.length; i++) {
    for (var j=0; j < data1.length; j++) {
    if (data[i][0] == data1[j][0]) {
    data.setValue(data1[j][1]);
    /*} else if (data[i][0] == "y") {
    data.setValue("Yes");
    }else{*/
    }
    }
    }
    }

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  2 роки тому +1

      range.createTextFinder("cat").matchEntireCell(true).replaceAllWith("cat & dog")

    • @giamar3026
      @giamar3026 2 роки тому

      @@ExcelGoogleSheets thank you, very much!

  • @ericjohnson1144
    @ericjohnson1144 5 років тому

    I'm trying to do this with rows, but i'm logging 0 each time.
    var lr = ss.getLastRow();
    var lookupRowValues = ss.getRange(4,2,lr,1).getValues()[0];
    var indexRow = lookupRowValues.indexOf("AH-POR-DIF-BLK") + 1;
    Logger.log(indexRow);
    what am I doing wrong?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  5 років тому +1

      rows return array of arrays. Watch my array series to understand what's happening and how to fix it. ua-cam.com/video/tZdSa6p3PHQ/v-deo.html&list=PLv9Pf9aNgemvD9NFa86_udt-NWh37efmD

    • @ericjohnson1144
      @ericjohnson1144 5 років тому

      ​@@ExcelGoogleSheets Thank you so much. I got it cleared up! I'm a supply chain manager for a small company, and I've been able to automate so much of my work thanks to your videos!

    • @prodigroup
      @prodigroup 3 роки тому

      What was the solution? This does not work for rows.

  • @vijaybabukommuri5125
    @vijaybabukommuri5125 2 роки тому

    How to use vlookup function or index match in appscript

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  2 роки тому

      You can't use the same functions in Apps Script, you have to build your own.

  • @computergeeks7546
    @computergeeks7546 6 років тому

    The log says "Undefined". Can you help me what's wrong with my script, @Learn Google Spreadsheets?
    As note: I have "Sheet1" and "Sheet2", and the column "Alfa", "Beta", Gamma".
    Here is my script:
    function myFunction(){
    var index = ColumnIndex("Sheet1","Beta");
    Logger.log(index);
    }
    function ColumnIndex(sheetname,columnlabel){
    var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetname);
    var lastColumnIndex = activeSheet.getLastColumn();
    var headers = activeSheet.getRange(1, 1, 1, lastColumnIndex).getValues()[0];
    var columnIndex = headers.indexOf(columnlabel)+1;
    }

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  6 років тому

      this line
      var columnIndex = headers.indexOf(columnlabel)+1;
      should be
      return headers.indexOf(columnlabel)+1;

    • @computergeeks7546
      @computergeeks7546 6 років тому

      Thank you. It works now! :-D

  • @Caldoyel
    @Caldoyel 5 років тому

    What can I do if I want to find a value in a column instead of a row?

    • @Caldoyel
      @Caldoyel 5 років тому

      Right now the lookupRangeValues is giving me an array of arrays but I want to search the array of arrays and return the array position I'm looking for. Is there a way to do that?

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  5 років тому +1

      convert array of array to an array. Something like this should do it mylist = mylist.map(function(r){ return r[0]; });

    • @Caldoyel
      @Caldoyel 5 років тому

      @@ExcelGoogleSheets Thank you so much! That did the trick.

  • @bouyya4085
    @bouyya4085 4 роки тому

    Hi, i need your help please, i need to know, how can I get the numbre of not_Empty Rows with Apps script pleaaaaaaase ??

    • @ExcelGoogleSheets
      @ExcelGoogleSheets  4 роки тому

      I'm not entirely sure what you're trying to do, but skillwise everything you need is in this video and series associated with it. ua-cam.com/video/gaC290XzPX4/v-deo.html

  • @CreemosEnJesucristo
    @CreemosEnJesucristo 6 років тому

    how can I execute script with a key like the enter ? Excelent ... God Bless You.