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
javascript google-apps-script google-sheets
New contributor
add a comment |
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
javascript google-apps-script google-sheets
New contributor
add a comment |
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
javascript google-apps-script google-sheets
New contributor
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
javascript google-apps-script google-sheets
New contributor
New contributor
New contributor
asked Nov 5 at 2:46
Scott G
82
82
New contributor
New contributor
add a comment |
add a comment |
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.
- When
- 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.
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
add a comment |
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.
add a comment |
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.
- When
- 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.
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
add a comment |
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.
- When
- 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.
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
add a comment |
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.
- When
- 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.
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.
- When
- 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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 5 at 2:57
Jordan Rhea
708723
708723
add a comment |
add a comment |
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.
Scott G is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password