Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. function copySheets() {
  2. var copySheetsContaining = Browser.inputBox("Copy sheets with names containing:");
  3. var destinationId = Browser.inputBox("Enter the destination spreadsheet ID:");
  4. if (sheetMatch(copySheetsContaining)){
  5. for (var i = 0; i < sheetsCount; i++){
  6. var sheet = sheets[i];
  7. var sheetName = sheet.getName();
  8. Logger.log(sheetName);
  9. if (sheetName.indexOf(copySheetsContaining.toString()) !== -1){
  10. Logger.log("COPY!");
  11. var destination = SpreadsheetApp.openById(destinationId);
  12. sheet.copyTo(destination);
  13. }
  14. }
  15. successAlert('copied')
  16. } else {
  17. noMatchAlert();
  18. }
  19. }
  20.  
  21. // determine if any sheets match the user input
  22. function sheetMatch(sheetMatch){
  23. for (var i = 0; i < sheetsCount; i++){
  24. var sheetName = sheets[i].getName();
  25. if (sheetName.indexOf(sheetMatch.toString()) !== -1){
  26. return true
  27. }
  28. }
  29. return false
  30. }
  31.  
  32. // alert if no sheets matched the user input
  33. function noMatchAlert() {
  34. var ui = SpreadsheetApp.getUi();
  35. var result = ui.alert(
  36. 'No Sheets Matched Your Input',
  37. "Try again and make sure you aren't using quotes.",
  38. ui.ButtonSet.OK);
  39. }
  40.  
  41. // alert after succesful action (only used in copy)
  42. function successAlert(action) {
  43. var ui = SpreadsheetApp.getUi();
  44. var result = ui.alert(
  45. 'Success!',
  46. "You're sheets were " + action + " successfully.",
  47. ui.ButtonSet.OK);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement