Skip to content

Instantly share code, notes, and snippets.

@9bow
Last active April 18, 2018 08:36
Show Gist options
  • Save 9bow/128b03fe09e7811a1ae8a4edec11b0a4 to your computer and use it in GitHub Desktop.
Save 9bow/128b03fe09e7811a1ae8a4edec11b0a4 to your computer and use it in GitHub Desktop.
Google Script for choosing the random name of the survey winner used in meetup.
function onOpen(e) {
// Where the menu button defined
SpreadsheetApp.getUi().createMenu('Vuetiful').addItem('추첨~ 얍!', 'randomPick').addToUi();
}
function randomPick() {
var sss = SpreadsheetApp.getActiveSpreadsheet();
var ss = sss.getSheetByName('Form Responses 1'); // <- Check the sheet name
var range = ss.getRange(1,1,ss.getLastRow(), 3); // <- Check the last parameter: how many cells to fetch (first 3)
var data = range.getValues();
var pickNum = 0;
for (;;) {
pickNum = Math.floor(Math.random() * data.length);
if (pickNum != 0) {
break;
}
}
SpreadsheetApp.getUi().alert("축하합니다~ "+ data[pickNum][1] +"님!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment