I am a GAS newbie and I am trying to automatically update a monthly budget report from another sheet to keep tab on my project expenses.
Budget sheet example: https://docs.google.com/spreadsheets/d/1ggYjZmGBLnfP-Wzq5dFKpfjaOZj78lgJr8LAl2GtV-I/edit?usp=sharing
I am trying to build a code that can match data from 'Actual' sheet based on a project name such as 'Project1' and then copy and paste the data from 'Salary', 'Goods', 'Expenses' etc. to corresponding cells in the Budget sheet based on the same project name. The budget sheet gets new rows as new budgets are added for the projects. In case the correct project name is not found in the budget sheet, then this should go unnoticed. I get the actual numbers from our ERP and will update the 'Actual' sheet whenever I get a new report from the ERP.
I have built an extra menu button with 'update' which I hope would perform the above action. The code looks as below so far:
(add row function adds automatically last row to the table and retains the formulas)
// global
var ss = SpreadsheetApp.getActive();
function onOpen() {
var ui = SpreadsheetApp.getUi();
var menu = ui.createMenu('Menu');
var item = menu.addItem('New Row', 'addRow');
var item2 = menu.addItem('Update', 'updateTable');
item.addToUi();
}
function addRow() {
var sh = ss.getActiveSheet(), lRow = sh.getLastRow();
var lCol = sh.getLastColumn(), range = sh.getRange("InsertFormulaRangeHere");
sh.insertRowsAfter(lRow -1, 1);
range.copyTo(sh.getRange(lRow,1,1,lCol), {contentOnly:true})
;
}
function updateTable() {
import
}
So far I have looked into getRange script and importange, vlookup and match formulas but I am lost.
Any advice how to go about this?