I am new to TypeScript and my goal today would be to sum up all the cell values in a column in an Excel file, based on the cell values in another column.
In my Excel file, I have the calendar weeks, stored in column U and the corresponding values for those calendar weeks in column R. As I mentioned at the beginning, my goal would be to sum up all the values for each calendar week (column R and corresponding column U), and save the overall sum for each week anywhere in an Excel file.
I have my Excel file on OneDrive online, with my data saved there. I open the Excel file and go into the "Automate Tab", which lets to have access to Office Scripts which is an equivalent of Excel VBA(but uses TypeScript programming language instead).
I attach the screens with what I was trying to do & what I have already done below.
- Here is how my data looks in my Excel file:
- Here is how I tried to solve the problem with the use of OfficeScripts. I was trying to solve the problem with a do-while loop.
function main(workbook: ExcelScript.Workbook)
{
const sheet = workbook.getWorksheet('Sheet1');
const range = sheet.getRange("A2:A6");
const x: number = 1;
let sum: number = 0;
do
{
if (sheet.getRange("A1").getOffsetRange(x,0) = '1')
{
sum = sum + sheet.getRange("A1").getOffsetRange(x,0)
}
} while(sheet.getRange("A").getColumn.);
}
I was making use of this SO post: VBA Code to sum values in one column based on the value in another column in excel when trying to solve the problem
If you have any suggestions as to how to solve the problem, your solutions are more than welcome. Thank you very much.