How to make a loop script for Google sheet?












2














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





























    2














    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



























      2












      2








      2







      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 loops google-apps-script google-sheets






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 21:50









      Rubén

      9,99043265




      9,99043265










      asked Nov 10 at 19:07









      Franc

      155




      155
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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',
          autoActivateHeartbeat: false,
          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









          1














          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
















          1














          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














          1












          1








          1






          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




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()