How to make a loop script for Google sheet?











up vote
3
down vote

favorite












I wanted to have a script that will change text to a hyperlink using script. I have column D in Google sheet from D1:D, for example:



12346
34566
23456
23455... and so on...


Currently, I'm using this script, this is for a specific tab named Sheet1 only.



function makeLink() {

var ss = SpreadsheetApp.getActiveSpreadsheet();

var aCell = ss.getRange("D1"), value = aCell.getValue();
aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
var aCell = ss.getRange("D2"), value = aCell.getValue();
aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
var aCell = ss.getRange("D3"), value = aCell.getValue();
aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
var aCell = ss.getRange("D4"), value = aCell.getValue();
aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
var aCell = ss.getRange("D5"), value = aCell.getValue();
}


Is there a way to to use looping for me to shorten my script?










share|improve this question




























    up vote
    3
    down vote

    favorite












    I wanted to have a script that will change text to a hyperlink using script. I have column D in Google sheet from D1:D, for example:



    12346
    34566
    23456
    23455... and so on...


    Currently, I'm using this script, this is for a specific tab named Sheet1 only.



    function makeLink() {

    var ss = SpreadsheetApp.getActiveSpreadsheet();

    var aCell = ss.getRange("D1"), value = aCell.getValue();
    aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
    var aCell = ss.getRange("D2"), value = aCell.getValue();
    aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
    var aCell = ss.getRange("D3"), value = aCell.getValue();
    aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
    var aCell = ss.getRange("D4"), value = aCell.getValue();
    aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
    var aCell = ss.getRange("D5"), value = aCell.getValue();
    }


    Is there a way to to use looping for me to shorten my script?










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I wanted to have a script that will change text to a hyperlink using script. I have column D in Google sheet from D1:D, for example:



      12346
      34566
      23456
      23455... and so on...


      Currently, I'm using this script, this is for a specific tab named Sheet1 only.



      function makeLink() {

      var ss = SpreadsheetApp.getActiveSpreadsheet();

      var aCell = ss.getRange("D1"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D2"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D3"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D4"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D5"), value = aCell.getValue();
      }


      Is there a way to to use looping for me to shorten my script?










      share|improve this question















      I wanted to have a script that will change text to a hyperlink using script. I have column D in Google sheet from D1:D, for example:



      12346
      34566
      23456
      23455... and so on...


      Currently, I'm using this script, this is for a specific tab named Sheet1 only.



      function makeLink() {

      var ss = SpreadsheetApp.getActiveSpreadsheet();

      var aCell = ss.getRange("D1"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D2"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D3"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D4"), value = aCell.getValue();
      aCell.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
      var aCell = ss.getRange("D5"), value = aCell.getValue();
      }


      Is there a way to to use looping for me to shorten my script?







      javascript






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 20:56









      FrankerZ

      15.4k72859




      15.4k72859










      asked Nov 10 at 19:07









      Franc

      233




      233
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can use something like this:



          i = 1
          while (true) {
          var range = ss.getRange("D" + i);
          var value = range.getValue();
          if(value == "") {
          break;
          }
          range.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
          i++;
          }





          share|improve this answer





















          • Awesome! This works perfectly to me Martin!. Thank you. You're the best!
            – Franc
            Nov 10 at 22:07










          • You're welcome Franc, glad I could help you. Can you please mark the answer as "Accepted" please?
            – Martin Urbanec
            Nov 10 at 22:14











          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%2f53242456%2fhow-to-make-a-loop-script-for-google-sheet%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You can use something like this:



          i = 1
          while (true) {
          var range = ss.getRange("D" + i);
          var value = range.getValue();
          if(value == "") {
          break;
          }
          range.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
          i++;
          }





          share|improve this answer





















          • Awesome! This works perfectly to me Martin!. Thank you. You're the best!
            – Franc
            Nov 10 at 22:07










          • You're welcome Franc, glad I could help you. Can you please mark the answer as "Accepted" please?
            – Martin Urbanec
            Nov 10 at 22:14















          up vote
          1
          down vote



          accepted










          You can use something like this:



          i = 1
          while (true) {
          var range = ss.getRange("D" + i);
          var value = range.getValue();
          if(value == "") {
          break;
          }
          range.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
          i++;
          }





          share|improve this answer





















          • Awesome! This works perfectly to me Martin!. Thank you. You're the best!
            – Franc
            Nov 10 at 22:07










          • You're welcome Franc, glad I could help you. Can you please mark the answer as "Accepted" please?
            – Martin Urbanec
            Nov 10 at 22:14













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You can use something like this:



          i = 1
          while (true) {
          var range = ss.getRange("D" + i);
          var value = range.getValue();
          if(value == "") {
          break;
          }
          range.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
          i++;
          }





          share|improve this answer












          You can use something like this:



          i = 1
          while (true) {
          var range = ss.getRange("D" + i);
          var value = range.getValue();
          if(value == "") {
          break;
          }
          range.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
          i++;
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 20:54









          Martin Urbanec

          2818




          2818












          • Awesome! This works perfectly to me Martin!. Thank you. You're the best!
            – Franc
            Nov 10 at 22:07










          • You're welcome Franc, glad I could help you. Can you please mark the answer as "Accepted" please?
            – Martin Urbanec
            Nov 10 at 22:14


















          • Awesome! This works perfectly to me Martin!. Thank you. You're the best!
            – Franc
            Nov 10 at 22:07










          • You're welcome Franc, glad I could help you. Can you please mark the answer as "Accepted" please?
            – Martin Urbanec
            Nov 10 at 22:14
















          Awesome! This works perfectly to me Martin!. Thank you. You're the best!
          – Franc
          Nov 10 at 22:07




          Awesome! This works perfectly to me Martin!. Thank you. You're the best!
          – Franc
          Nov 10 at 22:07












          You're welcome Franc, glad I could help you. Can you please mark the answer as "Accepted" please?
          – Martin Urbanec
          Nov 10 at 22:14




          You're welcome Franc, glad I could help you. Can you please mark the answer as "Accepted" please?
          – Martin Urbanec
          Nov 10 at 22:14


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242456%2fhow-to-make-a-loop-script-for-google-sheet%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          Bicuculline

          さくらももこ