I am working on a project that would greatly benefit from referencing function variables that change depending on the context of when those variables are called. For the script below, I am trying to figure out how to change which cell is being copied when running the CopyDataTest() function within the main function.
I have tried to define that variable in the main function and then call the CopyDataTest() function within the main function but that doesn’t appear to work.
This code below works great if I comment out line 39, but how do I get the CopyDataTest() function to use the value of var RangeSelect within the main function?
(function()
{
// Access the worksheets
var sheet1 = Api.GetSheet("Sheet1");
var sheet2 = Api.GetSheet("Sheet2");
//Sleep function
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
//Recalculate whole workbook again with all changes
function RecalculateWorkbook() {
Api.asc_calculate(Asc.c_oAscCalculateType.All);
}
function CopyDataTest() {
//Get Data from Sheet 1
var CopiedValue = sheet1.GetRange(RangeSelect).GetValue();
//Paste data into Sheet 1
sheet1.GetRange("B14").SetValue(CopiedValue);
}
//*******************************************************************
//Function: Main
//*******************************************************************
async function MainFunction() {
//Start Message
console.log('Greetings!');
//Declare variables for Copy Data Test
var RangeSelect = sheet1.GetRange("A2");
//Copy Data Test
CopyDataTest()
//Reclaculate Workbook
RecalculateWorkbook()
//Wait 5 seconds
await sleep(5000);
//End Message
console.log('Goodbye!');
}
MainFunction();
})();```