RemcoE33

u/theguynekstdoor - Randome word

Jul 11th, 2021 (edited)
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onOpen(e){
  2.   SpreadsheetApp.getUi().createMenu('Random')
  3.     .addItem('Run','randomWord')
  4.     .addToUi()
  5. }
  6.  
  7. function randomWord(){
  8.   const ss = SpreadsheetApp.getActiveSpreadsheet();
  9.   const inputValuesRaw = ss.getSheetByName('inputSheet')
  10.     .getRange('A2:A')
  11.     .getValues()
  12.     .flat();
  13.   const inputValues = inputValuesRaw.filter(value => { return value != ''});
  14.   const randomIndex = Math.round(Math.random() * inputValues.length);
  15.   const outputSheet = ss.getSheetByName('outputSheet')
  16.     .getRange('B2')
  17.     .setValue(inputValues[randomIndex - 1]);
  18. }
Add Comment
Please, Sign In to add comment