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:
If this was not what you want, I'm sorry.