Selecting a range from within a named range google sheets script











up vote
1
down vote

favorite












Is there any way to select a range specified from within another named range?



For example if I have a named range say "firstRange" and I want to get just the 2nd column from within that range to copy to another named range.



I can do this by copying cells individually with a for loop but it takes a long time.



Unfortunately
getRangeByName("firstRange").getRange(1,1,2) is not valid as getRange is not a method of getRangeByName



Thanks










share|improve this question







New contributor




Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    1
    down vote

    favorite












    Is there any way to select a range specified from within another named range?



    For example if I have a named range say "firstRange" and I want to get just the 2nd column from within that range to copy to another named range.



    I can do this by copying cells individually with a for loop but it takes a long time.



    Unfortunately
    getRangeByName("firstRange").getRange(1,1,2) is not valid as getRange is not a method of getRangeByName



    Thanks










    share|improve this question







    New contributor




    Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Is there any way to select a range specified from within another named range?



      For example if I have a named range say "firstRange" and I want to get just the 2nd column from within that range to copy to another named range.



      I can do this by copying cells individually with a for loop but it takes a long time.



      Unfortunately
      getRangeByName("firstRange").getRange(1,1,2) is not valid as getRange is not a method of getRangeByName



      Thanks










      share|improve this question







      New contributor




      Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Is there any way to select a range specified from within another named range?



      For example if I have a named range say "firstRange" and I want to get just the 2nd column from within that range to copy to another named range.



      I can do this by copying cells individually with a for loop but it takes a long time.



      Unfortunately
      getRangeByName("firstRange").getRange(1,1,2) is not valid as getRange is not a method of getRangeByName



      Thanks







      javascript google-apps-script google-sheets






      share|improve this question







      New contributor




      Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 5 at 2:46









      Scott G

      82




      82




      New contributor




      Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Scott G is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          How about this method? I think that there are several answers for your situation. So please think of this as one of them. The flow is as follows.



          Flow:




          • Range of values you want is retrieved from the source named-range by offset().


            • When getLastRow() is used to the named range, the returned value is the last row of the named range.



          • Retrieve the destination named-range.

          • Copy the retrieved source range to the destination range.


          Sample script:



          In this sample script, the 2nd column of named range of firstRange is copied to the named range of secondRange.



          var ss = SpreadsheetApp.getActiveSpreadsheet();

          // Retrieve source range.
          var sourceRange = ss.getRangeByName("firstRange");
          var src = sourceRange.offset(0, 1, sourceRange.getLastRow(), 1);

          // Retrieve destination range.
          var destinationRange = ss.getRangeByName("secondRange");

          // Copy from source range to destination range.
          src.copyTo(destinationRange);


          For example, if you want to copy the retrieved source range to 2nd column of the destination range, please modify var destinationRange = ss.getRangeByName("secondRange") as follows.



          var destinationRange = ss.getRangeByName("secondRange").offset(0, 1, 1, 1);


          References:




          • getLastRow()

          • offset()

          • copyTo()


          If this was not what you want, I'm sorry.






          share|improve this answer





















          • Perfect, that helped clean up a lot of code and it processes much faster now. Much appreciated!
            – Scott G
            Nov 6 at 18:23










          • @Scott G I'm glad your issue was solved. Thank you, too.
            – Tanaike
            Nov 6 at 21:59


















          up vote
          0
          down vote













          You can get the named range and then get the values which returns a multi-dimensional array. Then you can parse the values that you are looking for out of that. For example



          var parsed = SpreadsheetApp.getActiveSpreadsheet()
          .getRangeByName('namedRange')
          .getValues()
          .map(function(row) {
          return [row[1]];
          });


          This gets all the values from your named range and then maps over them and grabs the values from the second column (the 1 index in this example)



          I hope that helps.






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


            }
            });






            Scott G is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147669%2fselecting-a-range-from-within-a-named-range-google-sheets-script%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



            accepted










            How about this method? I think that there are several answers for your situation. So please think of this as one of them. The flow is as follows.



            Flow:




            • Range of values you want is retrieved from the source named-range by offset().


              • When getLastRow() is used to the named range, the returned value is the last row of the named range.



            • Retrieve the destination named-range.

            • Copy the retrieved source range to the destination range.


            Sample script:



            In this sample script, the 2nd column of named range of firstRange is copied to the named range of secondRange.



            var ss = SpreadsheetApp.getActiveSpreadsheet();

            // Retrieve source range.
            var sourceRange = ss.getRangeByName("firstRange");
            var src = sourceRange.offset(0, 1, sourceRange.getLastRow(), 1);

            // Retrieve destination range.
            var destinationRange = ss.getRangeByName("secondRange");

            // Copy from source range to destination range.
            src.copyTo(destinationRange);


            For example, if you want to copy the retrieved source range to 2nd column of the destination range, please modify var destinationRange = ss.getRangeByName("secondRange") as follows.



            var destinationRange = ss.getRangeByName("secondRange").offset(0, 1, 1, 1);


            References:




            • getLastRow()

            • offset()

            • copyTo()


            If this was not what you want, I'm sorry.






            share|improve this answer





















            • Perfect, that helped clean up a lot of code and it processes much faster now. Much appreciated!
              – Scott G
              Nov 6 at 18:23










            • @Scott G I'm glad your issue was solved. Thank you, too.
              – Tanaike
              Nov 6 at 21:59















            up vote
            0
            down vote



            accepted










            How about this method? I think that there are several answers for your situation. So please think of this as one of them. The flow is as follows.



            Flow:




            • Range of values you want is retrieved from the source named-range by offset().


              • When getLastRow() is used to the named range, the returned value is the last row of the named range.



            • Retrieve the destination named-range.

            • Copy the retrieved source range to the destination range.


            Sample script:



            In this sample script, the 2nd column of named range of firstRange is copied to the named range of secondRange.



            var ss = SpreadsheetApp.getActiveSpreadsheet();

            // Retrieve source range.
            var sourceRange = ss.getRangeByName("firstRange");
            var src = sourceRange.offset(0, 1, sourceRange.getLastRow(), 1);

            // Retrieve destination range.
            var destinationRange = ss.getRangeByName("secondRange");

            // Copy from source range to destination range.
            src.copyTo(destinationRange);


            For example, if you want to copy the retrieved source range to 2nd column of the destination range, please modify var destinationRange = ss.getRangeByName("secondRange") as follows.



            var destinationRange = ss.getRangeByName("secondRange").offset(0, 1, 1, 1);


            References:




            • getLastRow()

            • offset()

            • copyTo()


            If this was not what you want, I'm sorry.






            share|improve this answer





















            • Perfect, that helped clean up a lot of code and it processes much faster now. Much appreciated!
              – Scott G
              Nov 6 at 18:23










            • @Scott G I'm glad your issue was solved. Thank you, too.
              – Tanaike
              Nov 6 at 21:59













            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            How about this method? I think that there are several answers for your situation. So please think of this as one of them. The flow is as follows.



            Flow:




            • Range of values you want is retrieved from the source named-range by offset().


              • When getLastRow() is used to the named range, the returned value is the last row of the named range.



            • Retrieve the destination named-range.

            • Copy the retrieved source range to the destination range.


            Sample script:



            In this sample script, the 2nd column of named range of firstRange is copied to the named range of secondRange.



            var ss = SpreadsheetApp.getActiveSpreadsheet();

            // Retrieve source range.
            var sourceRange = ss.getRangeByName("firstRange");
            var src = sourceRange.offset(0, 1, sourceRange.getLastRow(), 1);

            // Retrieve destination range.
            var destinationRange = ss.getRangeByName("secondRange");

            // Copy from source range to destination range.
            src.copyTo(destinationRange);


            For example, if you want to copy the retrieved source range to 2nd column of the destination range, please modify var destinationRange = ss.getRangeByName("secondRange") as follows.



            var destinationRange = ss.getRangeByName("secondRange").offset(0, 1, 1, 1);


            References:




            • getLastRow()

            • offset()

            • copyTo()


            If this was not what you want, I'm sorry.






            share|improve this answer












            How about this method? I think that there are several answers for your situation. So please think of this as one of them. The flow is as follows.



            Flow:




            • Range of values you want is retrieved from the source named-range by offset().


              • When getLastRow() is used to the named range, the returned value is the last row of the named range.



            • Retrieve the destination named-range.

            • Copy the retrieved source range to the destination range.


            Sample script:



            In this sample script, the 2nd column of named range of firstRange is copied to the named range of secondRange.



            var ss = SpreadsheetApp.getActiveSpreadsheet();

            // Retrieve source range.
            var sourceRange = ss.getRangeByName("firstRange");
            var src = sourceRange.offset(0, 1, sourceRange.getLastRow(), 1);

            // Retrieve destination range.
            var destinationRange = ss.getRangeByName("secondRange");

            // Copy from source range to destination range.
            src.copyTo(destinationRange);


            For example, if you want to copy the retrieved source range to 2nd column of the destination range, please modify var destinationRange = ss.getRangeByName("secondRange") as follows.



            var destinationRange = ss.getRangeByName("secondRange").offset(0, 1, 1, 1);


            References:




            • getLastRow()

            • offset()

            • copyTo()


            If this was not what you want, I'm sorry.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 5 at 6:27









            Tanaike

            18.2k2921




            18.2k2921












            • Perfect, that helped clean up a lot of code and it processes much faster now. Much appreciated!
              – Scott G
              Nov 6 at 18:23










            • @Scott G I'm glad your issue was solved. Thank you, too.
              – Tanaike
              Nov 6 at 21:59


















            • Perfect, that helped clean up a lot of code and it processes much faster now. Much appreciated!
              – Scott G
              Nov 6 at 18:23










            • @Scott G I'm glad your issue was solved. Thank you, too.
              – Tanaike
              Nov 6 at 21:59
















            Perfect, that helped clean up a lot of code and it processes much faster now. Much appreciated!
            – Scott G
            Nov 6 at 18:23




            Perfect, that helped clean up a lot of code and it processes much faster now. Much appreciated!
            – Scott G
            Nov 6 at 18:23












            @Scott G I'm glad your issue was solved. Thank you, too.
            – Tanaike
            Nov 6 at 21:59




            @Scott G I'm glad your issue was solved. Thank you, too.
            – Tanaike
            Nov 6 at 21:59












            up vote
            0
            down vote













            You can get the named range and then get the values which returns a multi-dimensional array. Then you can parse the values that you are looking for out of that. For example



            var parsed = SpreadsheetApp.getActiveSpreadsheet()
            .getRangeByName('namedRange')
            .getValues()
            .map(function(row) {
            return [row[1]];
            });


            This gets all the values from your named range and then maps over them and grabs the values from the second column (the 1 index in this example)



            I hope that helps.






            share|improve this answer

























              up vote
              0
              down vote













              You can get the named range and then get the values which returns a multi-dimensional array. Then you can parse the values that you are looking for out of that. For example



              var parsed = SpreadsheetApp.getActiveSpreadsheet()
              .getRangeByName('namedRange')
              .getValues()
              .map(function(row) {
              return [row[1]];
              });


              This gets all the values from your named range and then maps over them and grabs the values from the second column (the 1 index in this example)



              I hope that helps.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                You can get the named range and then get the values which returns a multi-dimensional array. Then you can parse the values that you are looking for out of that. For example



                var parsed = SpreadsheetApp.getActiveSpreadsheet()
                .getRangeByName('namedRange')
                .getValues()
                .map(function(row) {
                return [row[1]];
                });


                This gets all the values from your named range and then maps over them and grabs the values from the second column (the 1 index in this example)



                I hope that helps.






                share|improve this answer












                You can get the named range and then get the values which returns a multi-dimensional array. Then you can parse the values that you are looking for out of that. For example



                var parsed = SpreadsheetApp.getActiveSpreadsheet()
                .getRangeByName('namedRange')
                .getValues()
                .map(function(row) {
                return [row[1]];
                });


                This gets all the values from your named range and then maps over them and grabs the values from the second column (the 1 index in this example)



                I hope that helps.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 5 at 2:57









                Jordan Rhea

                708723




                708723






















                    Scott G is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    Scott G is a new contributor. Be nice, and check out our Code of Conduct.













                    Scott G is a new contributor. Be nice, and check out our Code of Conduct.












                    Scott G is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147669%2fselecting-a-range-from-within-a-named-range-google-sheets-script%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()