Google Apps Script: Get Range in Sheets

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ • 79

  • @frdata
    @frdata 3 роки тому +7

    Exactly what I've been searching for. Comprehensive and clearly explained. You saved me a lot of time. Thank you so much

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

      You're very welcome! 😃

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

    I am new to Google App Script. Your tutorials are very well structurated and worked best for me. Thank you for that.

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

      Glad it helped! 😀

  • @zaidkhan-nb1er
    @zaidkhan-nb1er Рік тому +1

    ty love

    • @saperis
      @saperis  Рік тому

      You're welcome 😀

  • @vin81084
    @vin81084 8 місяців тому

    Thank you for this. Is there a way we can get multiple ranges in app script say A1:A5 and C1 to C5 ?

  • @lholhofox
    @lholhofox Рік тому

    Thank you very much for the video!! Very good and clear explanation!
    Keep'em coming!!

    • @saperis
      @saperis  Рік тому +1

      You are welcome! 😀

  • @ammarshbeb1840
    @ammarshbeb1840 Рік тому

    Thank you very much for the video .. what about blanks and formulas ?

    • @saperis
      @saperis  Рік тому

      Check the developer documentation to see how to retrieve this from a sheet: developers.google.com/apps-script/reference/spreadsheet

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

    best video tutorial ever! please, createTextFinder tool for some videos in the future 🙏

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

      Thanks for the feedback. I don't make any Apps Script videos on this channel anymore. See why: ua-cam.com/video/OHd_xEabivg/v-deo.html

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

    Thank you for the clear video. You really know how to teach!
    How would you use getRange when the first two parameters should be the row and column of the currentActiveCell followed up bij numRows and numColumns?

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

      If you want to access the current active cell you can use the getCurrentCell() method.
      This gives you back a range.
      The getRange() method also gives you back a range. Just that here you define the range by passing in the parameters of row, column, row count and column count.
      You can't use the getCurrentCell() method together with the getRange() method.

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

      @@saperis Thank you for the clear reply! ....kind regards Jan

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

    Gracias por tener un ingles tan claro. Lo entendí perfectamente. Y has sido muy didactica. Muy amable. Gracias!

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

      Estoy feliz de que te haya gustado 😀

  • @TheLichOmoi
    @TheLichOmoi 4 місяці тому

    I like to use indexof or match to make dynamic ranges as intended within the code. it's harder but i'm trying to find a better method of streamlining and debugging it

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

    Hi, thank you for this video. I also need to get a hyperlink that is added on some part of the text in cells. I guess I need to use getActiveSpreadsheet function but I don't know how to do it.

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

      With getAchtiveSpreadsheet you simply get the entire Google Sheets file that you currently have opened in your browser. Form there you need to use further methods to access the part of the data that you are interested in.

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

    Excelente, saludos desde Chile

  • @bernardsco7663
    @bernardsco7663 Місяць тому

    Very thankful ...

  • @alecallejas3043
    @alecallejas3043 Рік тому

    Great explanation, I have a question: what if for example I want to store a cell value as a variable; Sheet1 Cell B2 value Is stored as "Sales". What method should I apply? Thank you!!

    • @saperis
      @saperis  Рік тому +1

      To get the content of one specific cell you can use .getValue() on the range.
      developers.google.com/apps-script/reference/spreadsheet/range#getvalue

    • @alecallejas3043
      @alecallejas3043 Рік тому

      @@saperis Thank you!

  • @gokhanboyac7496
    @gokhanboyac7496 Рік тому

    Hello, can we export a certain range field as example a1:f15 jpeg.

    • @saperis
      @saperis  Рік тому

      I think that should be possible. Check this video to find out how to export a Sheets file: ua-cam.com/video/xUovS4fwqsg/v-deo.html

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

    Thank you, for the help !

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

      You're welcome! 😀

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

    Very interesting! I'm trying to get a variable range in a coulmn, so I think i need to get the range to lastRow of that Column. Is it possibile without a loop?

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

      I wouldn't use a loop to get data from a spreadsheet. I would much rather use the getDataRange() method. It gives you back all the data no matter how many rows it contains.

  • @fliich
    @fliich Рік тому

    Thanks for this tutorial. Very clear and concise. I was wondering is there a way to getRange() with a parameter you set in your function or by getting the current row or current cell? I'm having a hard time conceptualizing it this way.

    • @saperis
      @saperis  Рік тому

      To understand what parameters you can use, check the official Apps Script documentation. That's the easiest way to find out how to use methods: developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column

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

    Is there a way to get fixed selected cells from all sheets (except master sheet) to a master sheet?
    For eg, If I have a sheet for each day of a month and I want to compile data from all sheets to a master sheet

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

      That should be possible. We have a video on how to copy content from one sheet to another that might offer some ideas on how to accomplish your goal: ua-cam.com/video/xmtwWKYLJHs/v-deo.html

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

      @@saperis Thanks for the revert! It does to some extent, but I want to get data prospectively from all new sheets made to a master sheet, but the data should be added in a different row each time so that I have a compiled data at the end.

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

      @UC%F0%9F%98%80zKzrFTs7_vZGA3lU0IDSbQ Ok, well we have no video on what you are exactly trying to do. But I'm sure you'll get it done.

  • @Krishnadhurwey1986
    @Krishnadhurwey1986 Рік тому

    Please make a video for getting data from the rows which have true values..

    • @saperis
      @saperis  Рік тому

      Thank you for watching this video. I don't do any Apps Script videos anymore on this channel. But I invite you to check out the Google Workspace Developers UA-cam channel: www.youtube.com/@googleworkspacedevs

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

    is it possible to get ranges starting from the class Range? or do you always have to start from the class Sheet?

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

      You have to start from the class Sheet or Spreadsheet.

  • @МаркЛеонтьев-л4б

    Excellent teacher with excellent lessons) Please, can you tell me why google script logger shows ranges in different ways? For example, in the video when you used a1Notation, all results appeared in one row (not in different rows for better presenting information as other examples). I have the same problem: when I use getRange() with all 4 parameters (4, 14, 1, 23) , console.log() show me 23 rows :)) How could I solve this problem?

    • @saperis
      @saperis  Рік тому

      The logger shows you the data just like Apps Script sees it. That's why it's not represented in columns but instead in one row. There is no way of changing that.

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

    Hi how do i enable permissions. I went into the .json file and added the oauthScopes but it did not work

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

      What for permissions are you trying to enable? In the video tutorial you can see that I simply click my way through the default permissions.

  • @sudamshirke8243
    @sudamshirke8243 3 роки тому +1

    Great..👍👍

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

    Hi I can't see the option Script editor in google Sheets, how to fix that?

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

      Google has updated the Google Sheets menu since this video was made. Check Extensions > Apps Script.

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

    Great video! I just have one question about getNameByRange. When I try to use it, the log says its not a function but it shows the pop up dialog box when I input an argument. I then tried getNamedRange(Name) but it says that the input of a string is wrong. All I'm trying to do is get the length index of a column through script. Any help would be greatly appreciated!

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

      As you learned through the video there are multiple ways to get data from a sheet.
      If you chose to use the getNamedRange method I'm guessing you have created a named range within your sheet. In that case the parameter passed into the method has to be the name of the range.
      So if I named my range Person_and_Scores I have to use the method like so ON THE SPREADSHEET and not on the sheet:
      getNamedRange('Person_and_Scores');

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

      @@saperis Ah I see! Thanks!!

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

    My google sheets in tools, don't show Script editor. Why?

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

      Because Google updated the menu of Google Sheets since we've published this video. Go to 'Extensions' > 'Apps Script'.

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

      @@saperis Thank's! Your videos are amazing! :)

  • @ivanurbina2422
    @ivanurbina2422 Рік тому

    I love your tutorial.
    Question: Is there a way to set the column size of a google sheet by using javascript?
    I have been looking but could not find one. I want to use javascript, not the manual method.
    The google sheet I created is by javascript (where I got most of the methods from you, thank you); I want to add the capability of sizing a range of columns.
    Greatly appreciated.

    • @saperis
      @saperis  Рік тому

      I had a look at the Apps Script developer documentation. I don't think it's possible to set the width of a column using Apps Script.
      developers.google.com/apps-script/reference/spreadsheet

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

    could u plz make a video on how to get active user using app script. I have seen that if the user is not the owner then getActiveuser() function is not working desirably

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

      Thanks for watching. I don't do any Apps Script or Google Workspace videos anymore. Find out why in this video: ua-cam.com/video/OHd_xEabivg/v-deo.html

  • @Naveenkumar-lq3ik
    @Naveenkumar-lq3ik 2 роки тому

    Assume that c column has email_list , How to send in e-mail body the selected data A1:B7

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

      Well, you would have to write a separate script to actually send out the email. Our video tutorial here only demonstrates how to get data from a specific range within a Google Sheet.

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

    Is it possible instead of A1:B3. You instead use a cell with A1:B3

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

      I'm not sure if I understand your question. Yes, you can get any range you want and it doesn't have to be the same I used.

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

      @@saperis
      What I mean is... you used A1 notation as ( 'A1:B3') on your example. Is it possible to use a Cell value inside a sheet instead. Example G14 = A1:B3
      So new A1 Notation would be range('G14') instead. When I tried it it didn't work.

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

      @@DavenneChua The method expects an A1 notation and not a cell that contains A1 notations as its value. That's my assumption since both my tests and your tests have failed.

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

      @@saperis i see... is there a way to change it as such? To Get range from a cell value then use it for getrange. Or is there simpler way. If none that's ok. Thanks for your replies. :)

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

      @@saperis
      function ABCDEF()
      {
      var spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.setActiveSheet(spreadsheet.getSheetByName('SHEETNAME'), true);
      spreadsheet.getRange('C4:C49').setValue('ABCDEF');
      }
      if possible I just need C4:C49 to be from a cell G14 = C4:C49

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

    Those examples didn't work form me. I need the lastrow from lastcolumn. But lastcolumn don't have all the rows with values. So the last column have less values than the other columns. I can't find the right method for this issue. But I will find it! ;o)

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

      Maybe also check the method getLastColumn(): developers.google.com/apps-script/reference/spreadsheet/sheet#getlastcolumn
      And also check getLastRow(): developers.google.com/apps-script/reference/spreadsheet/sheet#getlastrow

  • @dornescu.lucian
    @dornescu.lucian 2 роки тому

    Hello,
    This line of code uses the id entered manually in the script
    let copyFile = DriveApp.getFileById('1GhpGpHM......').makeCopy(),
    copyID = copyFile.getId(),
    copyDoc = DocumentApp.openById(copyID),
    How could I use the ID that can be found manually written in the google spreadsheet, so that if I change it from the spreadsheet, it will also change automatically in the script. I have a list of IDs associated with some templates.
    I used :
    var ID_template = ss.getRangeByName('ID_template').getValue;
    and then
    let copyFile = DriveApp.getFileById(ID_template).makeCopy(),
    copyID = copyFile.getId(),
    copyDoc = DocumentApp.openById(copyID),
    but without any result.
    Can something be done about this?

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

      The getRangeByName() method you are using is only for named ranges in a sheet. So that will never work the way you are using it.
      Instead, get that file ID by referencing the exact cell like ss.getRange('A1') or whatever cell it is in.
      Very important when using Apps Script: read the official documentation to find out what methods do. developers.google.com/apps-script/reference/spreadsheet

  • @alexshvetz58
    @alexshvetz58 4 місяці тому

    👍

  • @TuanTran-db3uv
    @TuanTran-db3uv 2 роки тому

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName('Thông tin liên hệ (Câu trả lời)');
    var emailTo = sheet.getRange(sheet.getLastRow(), 3).getValue();
    I don't khow why there is an error "Cannot read property 'getRange' of null"(Sorry, i'm new)

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

      I can't tell by looking at the code you shared here.
      Maybe there is a typo?

    • @TuanTran-db3uv
      @TuanTran-db3uv 2 роки тому

      @@saperis Thank you very much. I found the problem