I am trying to set up an assignment sheet for my work team. I have a script to move a selected range from one sheet to another, but is there a way to modify it to have the person doing the assigning to fill in the tab name to which the selection should be moved?
This is my current move script:
​function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('Move')
.addItem('Bryan', 'assignBryan')
.addToUi();
}
function assignBryan() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
sheet = ss.getActiveSheet(),
sheetName = sheet.getName(),
data = sheet.getDataRange().getValues();
if (sheetName !== 'Master') {
var range = sheet.getActiveRange(),
startRow = range.getRowIndex(),
numRows = range.getNumRows(),
numCols = range.getNumColumns()
if (numCols == 7) {
if (data.length > 1) {
var values = range.getValues(),
nextSheet = ss.getSheetByName("Bryan"),
lastRow = nextSheet.getLastRow();
nextSheet.getRange(lastRow+1,1,numRows,7).setValues(values);
sheet.deleteRows(startRow,numRows);
}
}
}
}
Is there a way to identify the destination sheet with manual input from the user in a dialog box?
Here's a link to the test sheet I'm working on: https://docs.google.com/spreadsheets/d/1JvfUQbzroo7NjZcXXzCtwobeFK8I2iZ_7uUmjrYMKpU
Best Answer
This answer addresses the OP's goal of selecting the "next sheet" option from a drop down list in a dialogue. It should be considered as an example of one method, and possibly requires further fine-tuning, error checking and/or validation.
The OP has an onOpen menu. Currently this lists several function, each of which is a permutation of the source and target sheet. In this answer, the onOpen menu is a single single function to launch the Dialog
.addItem('Select Next', 'jqueryOpenMyDialog')
assignnext(value);
to move the data.assignnext(value);
is identical to the existingassignBryan()
except that:nextSheet = ss.getSheetByName("Bryan"),
is replaced bynextSheet = ss.getSheetByName(value),
.jquerygs.gs
jqueryhtml.html