-1
function ABCDEF()
{
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('SHEETNAME'), true);
spreadsheet.getRange('A1:A17').setValue('ABCDEF');
}

if possible I just need A1:A17 to be from a cell G14 with value = A1:A17

player0
  • 124,011
  • 12
  • 67
  • 124
BDC
  • 1
  • 2
  • Do you mean you want the range A1:A17 of sheet SHEETNAME to be filled with the value for G14 (what sheet?)? – TheWizEd Aug 22 '22 at 15:02
  • ah no, I want spreadsheet.getRange('A1:A17') to be spreadsheet.getRange('G14') G14 with value = A1:A17 so sscript will be spreadsheet.getRange('A1:A17') then set value to abcdef – BDC Aug 22 '22 at 15:08
  • What will be the value of the cell `G14` ? – Marios Aug 22 '22 at 15:09
  • reason for this is G14 is , A1:A14 may extend or shorten with data. so G14 counts the data G14 = "A1:A14" – BDC Aug 22 '22 at 15:11
  • you want to put all the data of A1:A14 to a single cell G14? If yes how that will be? comma separated for example? It would be better if you edit your question and provide an example (screenshot). – Marios Aug 22 '22 at 15:13
  • basically >>> spreadsheet.getRange('A1:A17') << range needs to be updated based on G14 VALUE – BDC Aug 22 '22 at 15:13
  • So again to be clear, G14 contains the string "A1:A17"? Then you want to get the values from that range? And then what do want to do with them? Both are in sheet SHEETNAME? – TheWizEd Aug 22 '22 at 15:15
  • https://ibb.co/3095xhm < pic – BDC Aug 22 '22 at 15:21
  • hope the pic helps – BDC Aug 22 '22 at 15:22
  • Yes all are in the same sheet/workbook then I want to setValue('ABCEF') in the pic it was ABC only set value will just put any text as I tested. – BDC Aug 22 '22 at 15:24

1 Answers1

0

Here is an example of how I would do it.

Get the range from G14, set the range equal to the value from G14 and then setValue()

function setRange() {
  try {
    let spread = SpreadsheetApp.getActiveSpreadsheet();
    let sheet = spread.getSheetByName("Sheet1");
    let range = sheet.getRange("G14").getValue();
    sheet.getRange(range).setValue("ABC");
  }
  catch(err) {
    console.log(err);
  }
}
TheWizEd
  • 7,517
  • 2
  • 11
  • 19
  • this worked. Thanks. sorry for the incorrect statements, but this worked flawless – BDC Aug 22 '22 at 15:37
  • Slight correction but no difference in results removed `range =` from `range = sheet.getRange(range)...` – TheWizEd Aug 22 '22 at 15:39