Sub Ranges Should Pull Loaded Stats from Parent Range if Loaded

Sub Ranges Should Pull Loaded Stats from Parent Range if Loaded
0

Upvotes

Upvote

 Mar 20 2022
0 Comments 
New

As context.syncs are to be avoided I have started loading all properties in the beginning of my routines. I often will use regex to find specific ranges of data I'm working with to avoid having to ask for user input. In VBA I would use a function to return a range, but w/ Office-JS, if I return a range, I need to load the values. So, I switched to return an object w/ the indexes of the data I want and using a for loop to go through the data.

 

What I would like to do, is be able to make a subrange from those indexes so my for loop can start at zero and my code is more readable. Currently I have to start my for loop using the entire "UsedRange" and then the start number/end number and column index are all variables I pull from the object returned previously from the function. I would love to start the for loop by drilling down to the desired range and then starting the loop at 0. Does that make sense? 

 

IE: This is a simple example of what I would expect to work:

 

 

var rng = ws.getRange("A1:B2")
rng.values = "Hello World"
await context.sync(); // Load Fake Data

rng.load(["values"])
await context.sync(); //Load Values into rng
var sub_rng = rng.getRow(0)
sub_rng.select();
console.log(sub_rng.values[0][0]) //sub_rng has lost values