问题
I have this statement:
var destinationRange = destinationSheet.getRange("D26:E39");
and want to replace it with
var destinationRange = destinationSheet.getRange(daGrowaRange);
The reason I want to use daGrowaRange is not just cause da name, but that the range is not always the same.
- D is a fixed constant value and never changes
- E is a fixed constant value and never changes
BUT
- 26 is dynamic and changes and
- 39 is an offset based on the 26 (in this case 13 so 39 = 26+13, but the 13 is a variable value also).
I am sure that I could put this together in some ugly ass way, but I am sick of looking at my crappy code and want to learn how you crackz out there make it nice.
Thank you
回答1:
You can use Template literals to accomplish this task:
const dValue = 26;
const eValue = dValue + 13;
const daGrowaRange = `D${dValue}:E${eValue}`;
const destinationRange = destinationSheet.getRange(daGrowaRange);
来源:https://stackoverflow.com/questions/63458072/build-range-with-string