I’m working on a customer order form in Google Sheets and need to move information from my input sheet to a master database sheet. Back when I used Excel with VBA, I could easily do this with something like orderData.getValue("!OrderForm:B5") = customerInfo.getValue("!Database:C10").
I’m pretty new to Google Sheets scripting and wondering what’s the best way to accomplish this same task? I need to grab values from specific cells in one sheet and put them into another sheet automatically. Any code examples would be really helpful since I’m still learning the Google Apps Script syntax.
yeah, getRange works great, but try batch operations for moving lots of data. somethin like var values = sourceSheet.getRange('A1:D10').getValues(); targetSheet.getRange('A1:D10').setValues(values); beats cell-by-cell transfers every time. cut my invoicing setup time in half.
Here’s what saved me tons of headaches building similar order systems: use getDataRange() to find the next empty row instead of hardcoding references. Just do var lastRow = targetSheet.getDataRange().getLastRow(); targetSheet.getRange(lastRow + 1, 1).setValue(sourceValue); and it’ll automatically append new orders. Also, wrap your transfers in try-catch blocks - Google Sheets throws errors if someone renames or deletes sheets. The syntax is weird coming from VBA, but the web triggers make automation way smoother once you get it.
Google Apps Script works differently than VBA but it’s pretty straightforward. You’ll mainly use getRange() and getValue() or setValue(). Here’s what I do:
function transferData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = ss.getSheetByName('OrderForm');
var targetSheet = ss.getSheetByName('Database');
var sourceValue = sourceSheet.getRange('B5').getValue();
targetSheet.getRange('C10').setValue(sourceValue);
}
This pulls the value from B5 in your OrderForm sheet and drops it into C10 of your Database sheet. For multiple cells, use getValues() and setValues() instead - way more efficient for bigger transfers. Works great for customer forms like yours.