Google Scripts - Data Mapping with For Loop Very Slow to Load Data

33 Views Asked by At

I am fairly new to Google Script. I have been translating a guy's code from VBA to write my own database for my properties. The goal is to have the property data stored on a Property Database sheet, and have another 'Summary Sheet' that allows me to view the data for a selected property, edit it, and update it to the database.

I'm using data mapping by putting the cell a1Notation from the Summary Sheet above the corresponding cells in the database sheet. I use a for loop to load the selected property data from the database sheet into the summary sheet, which is executed using onedit when a property is selected. The problem is it is crazy slow. See below. Is there anything I can do to speed this up? Thank you!

Image of Summary Sheet: enter image description here

Image of Property Database Sheet (Continues to Column 43): enter image description here

Definitions:

var PropRow, PropCol, PropID
var app = SpreadsheetApp; 
var activeSheet = app.getActiveSpreadsheet(); //Get current active spreadsheet
var sheetProp = activeSheet.getSheetByName('Properties');
var sheetPropDB = activeSheet.getSheetByName('PropDB');

Loads Property data from Property Database (sheetPropDB) to Summary Sheet (sheetProp). This is the part that is very slow:

function Property_Load(){
  sheetProp.activate(); 
  PropRow = sheetProp.getRange('B7').getValue();
  
  for(PropCol = 3; PropCol<43; PropCol++){
    var dataLOC = sheetPropDB.getRange(2,PropCol).getValue(); // gets data mapping cell addresses from PropDB tab 
    var dataVAL = sheetPropDB.getRange(PropRow,PropCol).getValue(); //gets values of cells in PropDB sheet located at the selected properties PropRow and for each PropCol
    var dataPASTE = sheetProp.getRange(dataLOC);  // highlights the cells on the Property tab given by the addresses in dataLOC

    dataPASTE.setValue(dataVAL); // pastes the values from the propDB selected property row into the specified cells of the property tab
    
  }
}
0

There are 0 best solutions below