質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
date

dateは、date型や日付に関する関数や処理についてのタグです

Google Apps Script

Google Apps ScriptはGoogleの製品と第三者のサービスでタスクを自動化するためのJavaScriptのクラウドのスクリプト言語です。

Q&A

解決済

1回答

1702閲覧

【GAS】取得した日付データをスプレッドシートのセルに補充する方法

donguriko

総合スコア30

date

dateは、date型や日付に関する関数や処理についてのタグです

Google Apps Script

Google Apps ScriptはGoogleの製品と第三者のサービスでタスクを自動化するためのJavaScriptのクラウドのスクリプト言語です。

0グッド

0クリップ

投稿2021/06/27 09:18

編集2021/06/27 09:30

基本的な質問で申し訳ありません。
非エンジニアのGASビギナーです。
GAS本を見たりしましたが、どのように修正すればよいのかが分かりません。
不勉強で恐縮ですが修正方法のアドバイスをいただけますでしょうか?
お手数ですがビギナーでも分かるよう解説いただけると助かります。

<前提・実現したいこと>
取得した日付データをスプレッドシートのセルに補充させたいです。
具体的には、
日付1:yyyy年mm月dd日 + (曜日) >> セルU3とAD3に補充
日付2:yyyy年mm月dd日 + (曜日) >> セルU64にAD64に補充

<発生している問題・エラーメッセージ>
Exception: The parameters (String) don't match the method signature for SpreadsheetApp.Range.setValues.
myFunction2 @ 週次入力シート作成20210609.gs:137

※本日GAS起動だと下ソースコード(条件6)に合致。
★部でエラーとなり、処理が止まります。
文字列日付の場合、「getRangeとsetValuesは使えない」という意味のエラーか?

<該当のソースコード>
長文となりますが、記載したコード全文を記載します。

function myFunction2() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const date = Utilities.formatDate(new Date(), 'Asia/Tokyo','yyyyMMdd'); //シート名生成処理の際、文字列にできるようにconstではなくletで定義 let mySheetName =""; let closeDay =""; //「入力シート」のシート名指定準備_「開始日」曜日の判定 const openDate = new Date() const o1 = Utilities.formatDate(openDate, 'Asia/Tokyo', 'yyyyMMdd'); const o2 = Utilities.formatDate(openDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const openDayN = openDate.getDay() const array = ['日', '月', '火', '水', '木', '金', '土']; const openDay = '(' + array[openDayN]+ ')'; console.log(o1 + openDay + "~"); mySheetName = o1 + "~"; console.log(mySheetName); // すでに「入力シート」が作られていたらメッセージ1を表示し、処理終了 if (ss.getSheetByName("ひな形 のコピー") != null) { Browser.msgBox("今週分のシートはすでに「作成済」です。\n処理を中止します。\nファイル内のシートをもう一度確認してください。"); //存在しない場合は、処理継続 }else{   //「ひな形」シートをコピーし(一番右に追加される)新「入力シート」を左から2番目に移動する。 const sh_temp1 = ss.getSheetByName("ひな形"); sh_temp1.copyTo(ss).activate(); ss.moveActiveSheet(2); //「入力シート」の氏名(C2)の内容を「入力シート」氏名欄(E3、E64)にコピー const sh_temp2 = ss.getSheetByName("入力シート"); const copyValue1 = sh_temp2.getRange('C2').getValues(); console.log(copyValue1); const sh_new = ss.getSheetByName("ひな形 のコピー"); sh_new.getRange('E3').setValues(copyValue1); sh_new.getRange('E64').setValues(copyValue1); //「入力シート」の項目①(C6)の内容を「入力シート」項目①欄(F5、F66)にコピー const copyValue2 = sh_temp2.getRange('C6').getValues(); console.log(copyValue2); sh_new.getRange('F5').setValues(copyValue2); sh_new.getRange('F66').setValues(copyValue2); //「入力シート」の項目②(C7)の内容を「入力シート」項目②欄(F6、F67)にコピー const copyValue3 = sh_temp2.getRange('C7').getValues(); console.log(copyValue3); sh_new.getRange('F6').setValues(copyValue3); sh_new.getRange('F67').setValues(copyValue3); //「入力シート」の項目③(C8)の内容を「入力シート」項目③欄(F7、F68)にコピー const copyValue4 = sh_temp2.getRange('C8').getValues(); console.log(copyValue4); sh_new.getRange('F7').setValues(copyValue4);  sh_new.getRange('F68').setValues(copyValue4); //「入力シート」の日付欄(U3)の指定準備_終了日の判定 //(条件1)「開始日」が月曜のとき「終了日」は4日後をセット if (openDayN ==1) { closeDate =new Date(openDate.setDate(openDate.getDate() + 4)); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(‘+array[closeDayN]+’)'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValues(o1 + openDay);  sh_new.getRange('AD3').setValues(c + closeDay); sh_new.getRange('U64').setValues(o1 + openDay); sh_new.getRange('AD64').setValues(c + closeDay); //(条件2)火曜のとき「終了日」は3日後をセット }else if (openDayN ==2) { closeDate =new Date(openDate.setDate(openDate.getDate() + 3)); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(‘+array[closeDayN]+’)'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValues(o1 + openDay); sh_new.getRange('AD3').setValues(c + closeDay); sh_new.getRange('U64').setValues(o1 + openDay); sh_new.getRange('AD64').setValues(c + closeDay); //(条件3)水曜のとき「終了日」は2日後をセット }else if (openDayN ==3) { closeDate =new Date(openDate.setDate(openDate.getDate() + 2)); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' +array[closeDayN] +')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValues(o1 + openDay); sh_new.getRange('AD3').setValues(c + closeDay); sh_new.getRange('U64').setValues(o1 + openDay); sh_new.getRange('AD64').setValues(c + closeDay); //(条件4)木曜のとき「終了日」は1日後をセット }else if (openDayN ==2) { closeDate =new Date(openDate.setDate(openDate.getDate() + 1)); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(‘+array[closeDayN]+’)'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValues(o1 + openDay); sh_new.getRange('AD3').setValues(c + closeDay); sh_new.getRange('U64').setValues(o1 + openDay); sh_new.getRange('AD64').setValues(c + closeDay); //(条件5)金曜のとき }else if (openDayN ==1) { closeDate =new Date(openDate.setDate(openDate.getDate())); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(‘+array[closeDayN]+’)'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValues(o1 + openDay); sh_new.getRange('AD3').setValues(c + closeDay); sh_new.getRange('U64').setValues(o1 + openDay); sh_new.getRange('AD64').setValues(c + closeDay); //(条件6)それ以外のとき 当日日付をセット }else { closeDate =new Date(openDate.setDate(openDate.getDate())); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '('+array[closeDayN]+')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValues(o1 + openDay); //←★ここで失敗している sh_new.getRange('AD3').setValues(c + closeDay); sh_new.getRange('U64').setValues(o1 + openDay); sh_new.getRange('AD64').setValues(c + closeDay); //「入力シート」のシート名編集 sh_new.setName(mySheetName); } } //シート追加済のメッセージ2を表示 Browser.msgBox("今週分の入力シートを作成しました。内容を入力してください。"); }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

1.setValues()を用いて単一セルの値を書き込む場合は、引数に2次元配列の形でデータを指定する必要があります。

sh_new.getRange('U3').setValues(o1 + openDay); //←★ここで失敗している    ↓ sh_new.getRange('U3').setValues([[o1 + openDay]]); ※ 「o1+openday」 は「20210701(日)」という文字列なので、そのままsetValues()に渡すとエラーになる。 [[ ]]で囲って2次元配列にする必要がある。

または、setValues()の代わりに、setValue()を使えば2次元配列を使わずに単一セルの値を書き込めます。
どちらにするかは好みですが、直すならばこちらの方が楽だと思います。

sh_new.getRange('U3').setValues(o1 + openDay); //←★ここで失敗している    ↓ sh_new.getRange('U3').setValue(o1 + openDay); ※setValue()関数を使えば、書き込みたい値をそのまま渡せる。 ```    注意:書き込もうとしているデータがgetValuesで取得したデータの場合は、2次元配列として取得されるため、setValues()を使ってもエラーになりません。 ```diff //「入力シート」の氏名(C2)の内容を「入力シート」氏名欄(E3、E64)にコピー const sh_temp2 = ss.getSheetByName("入力シート"); const copyValue1 = sh_temp2.getRange('C2').getValues();  ←copyValue1はgetValues()で取得されているので2次元配列。 console.log(copyValue1); const sh_new = ss.getSheetByName("ひな形 のコピー"); sh_new.getRange('E3').setValues(copyValue1);  ←2次元配列をそのままsetValuesに渡すのでエラーにならない。 sh_new.getRange('E64').setValues(copyValue1); ←同上

 

2.質問と直接関係はないですが、他の行で引用符が揃っていない部分があります。
('と’のペアになってしまっています)

エラーで停止したりはしませんが、このままだと意図しない結果になると思われます。

diff

1//「入力シート」の日付欄(U3)の指定準備_終了日の判定 2//(条件1)「開始日」が月曜のとき「終了日」は4日後をセット 3 if (openDayN ==1) { 4 closeDate =new Date(openDate.setDate(openDate.getDate() + 4)); 5 const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); 6 const closeDayN = closeDate.getDay() 7- const closeDay = '(‘+array[closeDayN]+’)'; 8+ const closeDay = '(' + array[closeDayN] + ')';

追記:
修正後の全体コードは下記のようになります。

function myFunction2() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const date = Utilities.formatDate(new Date(), 'Asia/Tokyo', 'yyyyMMdd'); //シート名生成処理の際、文字列にできるようにconstではなくletで定義 let mySheetName = ""; let closeDay = ""; //「入力シート」のシート名指定準備_「開始日」曜日の判定 const openDate = new Date() const o1 = Utilities.formatDate(openDate, 'Asia/Tokyo', 'yyyyMMdd'); const o2 = Utilities.formatDate(openDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const openDayN = openDate.getDay() const array = ['日', '月', '火', '水', '木', '金', '土']; const openDay = '(' + array[openDayN] + ')'; console.log(o1 + openDay + "~"); mySheetName = o1 + "~"; console.log(mySheetName); // すでに「入力シート」が作られていたらメッセージ1を表示し、処理終了 if (ss.getSheetByName(mySheetName) != null) { Browser.msgBox("今週分のシートはすでに「作成済」です。\n処理を中止します。\nファイル内のシートをもう一度確認してください。");   return; //存在しない場合は、処理継続 } else { //「週報ひな形」シートをコピーし(一番右に追加される)新「入力シート」を左から2番目に移動する。 const sh_temp1 = ss.getSheetByName("週報ひな形"); const sh_new = sh_temp1.copyTo(ss) ss.moveActiveSheet(2); //「目標入力シート」の氏名(C2)の内容を「入力シート」氏名欄(E3、E64)にコピー const sh_temp2 = ss.getSheetByName("目標入力シート"); const copyValue1 = sh_temp2.getRange('C2').getValues(); console.log(copyValue1); sh_new.activate() sh_new.getRange('E3').setValue(copyValue1); sh_new.getRange('E64').setValue(copyValue1); //「目標入力シート」の目標①(C6)の内容を「入力シート」目標①欄(F5、F66)にコピー const copyValue2 = sh_temp2.getRange('C6').getValues(); console.log(copyValue2); sh_new.getRange('F5').setValue(copyValue2); sh_new.getRange('F66').setValue(copyValue2); //「目標入力シート」の目標②(C7)の内容を「入力シート」目標②欄(F6、F67)にコピー const copyValue3 = sh_temp2.getRange('C7').getValues(); console.log(copyValue3); sh_new.getRange('F6').setValue(copyValue3); sh_new.getRange('F67').setValue(copyValue3); //「目標入力シート」の目標③(C8)の内容を「入力シート」目標③欄(F7、F68)にコピーにコピー const copyValue4 = sh_temp2.getRange('C8').getValues(); console.log(copyValue4); sh_new.getRange('F7').setValue(copyValue4); sh_new.getRange('F68').setValue(copyValue4); //「入力シート」の日付欄(U3)の指定準備_終了日の判定 //(条件1)「開始日」が月曜のとき「終了日」は4日後をセット if (openDayN == 1) { closeDate = new Date(openDate.setDate(openDate.getDate() + 4)); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AD3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AD64').setValue(c + closeDay); //(条件2)火曜のとき「終了日」は3日後をセット } else if (openDayN == 2) { closeDate = new Date(openDate.setDate(openDate.getDate() + 3)); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件3)水曜のとき「終了日」は2日後をセット } else if (openDayN == 3) { closeDate = new Date(openDate.setDate(openDate.getDate() + 2)); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件4)木曜のとき「終了日」は1日後をセット } else if (openDayN == 2) { closeDate = new Date(openDate.setDate(openDate.getDate() + 1)); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件5)金曜のとき } else if (openDayN == 1) { closeDate = new Date(openDate.setDate(openDate.getDate())); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件6)それ以外のとき 当日日付をセット } else { closeDate = new Date(openDate.setDate(openDate.getDate())); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); } //「入力シート」のシート名編集 sh_new.setName(mySheetName); } //シート追加済のメッセージ2を表示 Browser.msgBox("今週分の入力シートを作成しました。内容を入力してください。"); }

投稿2021/06/27 10:29

編集2021/06/27 12:09
退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

donguriko

2021/06/27 11:31 編集

qnoirさま、お忙しい中早々の回答ありがとうございます!! setValue()を使用なのですね。。。大変失礼いたしました。また、引用符の指摘もありがとう ございました。コード修正しましたら、セルへのデータ補充うまくいきました。(感謝) が、最後の処理のBrowser.msgBoxで定義したポップアップMsgが表示されませんでした。(涙) 別のGASでは、同じコード記載で想定通りにポップアップMsgが表示されていたのですが、 今回は表示されません。 又、すでに同名のシートがファイル内に存在している場合にエラーとし、 ポップアップ表示させたくて、下のコードを記載したのですがココも うまくmsg表示がされません。 // すでに「入力シート」が作られていたらメッセージ1を表示し、処理終了 if (ss.getSheetByName("mySheetName★") != null) { Browser.msgBox("今週分のシートはすでに「作成済」です。\n処理を中止します。\nファイル内のシートをもう一度確認してください。"); ★上の全文コードでは誤って、☆と記載していました。申し訳ありません。 if (ss.getSheetByName("ひな形 のコピー☆") != null) { どこがマズイのかと修正方法、追加で教えていただけないでしょうか? お手数をおかけいたしまして申し訳ありません。
退会済みユーザー

退会済みユーザー

2021/06/27 11:28 編集

直したときに、どこか中括弧({})を誤って削除していませんか? こちらでは正常にポップアップが表示されています。 もう一度コード確認していただくか、現状の「ポップアップが表示されないコード」をそっくりそのまま質問欄に記載していただけないでしょうか。
donguriko

2021/06/27 11:36

お手数をおかいたしまして本当に申し訳ありません。 下に修正した全文コードを再掲させていただきます。 <コード全文> function myFunction2() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const date = Utilities.formatDate(new Date(), 'Asia/Tokyo','yyyyMMdd'); //シート名生成処理の際、文字列にできるようにconstではなくletで定義 let mySheetName =""; let closeDay =""; //「入力シート」のシート名指定準備_「開始日」曜日の判定 const openDate = new Date() const o1 = Utilities.formatDate(openDate, 'Asia/Tokyo', 'yyyyMMdd'); const o2 = Utilities.formatDate(openDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const openDayN = openDate.getDay() const array = ['日', '月', '火', '水', '木', '金', '土']; const openDay = '(' + array[openDayN]+ ')'; console.log(o1 + openDay + "~"); mySheetName = o1 + "~"; console.log(mySheetName); // すでに「入力シート」が作られていたらメッセージ1を表示し、処理終了 if (ss.getSheetByName("mySheetName") != null) { Browser.msgBox("今週分のシートはすでに「作成済」です。\n処理を中止します。\nファイル内のシートをもう一度確認してください。"); //存在しない場合は、処理継続 }else{   //「週報ひな形」シートをコピーし(一番右に追加される)新「入力シート」を左から2番目に移動する。 const sh_temp1 = ss.getSheetByName("週報ひな形"); sh_temp1.copyTo(ss).activate(); ss.moveActiveSheet(2); //「目標入力シート」の氏名(C2)の内容を「入力シート」氏名欄(E3、E64)にコピー const sh_temp2 = ss.getSheetByName("目標入力シート"); const copyValue1 = sh_temp2.getRange('C2').getValues(); console.log(copyValue1); const sh_new = ss.getSheetByName("週報ひな形 のコピー"); sh_new.getRange('E3').setValue(copyValue1); sh_new.getRange('E64').setValue(copyValue1); //「目標入力シート」の目標①(C6)の内容を「入力シート」目標①欄(F5、F66)にコピー const copyValue2 = sh_temp2.getRange('C6').getValues(); console.log(copyValue2); sh_new.getRange('F5').setValue(copyValue2); sh_new.getRange('F66').setValue(copyValue2); //「目標入力シート」の目標②(C7)の内容を「入力シート」目標②欄(F6、F67)にコピー const copyValue3 = sh_temp2.getRange('C7').getValues(); console.log(copyValue3); sh_new.getRange('F6').setValue(copyValue3); sh_new.getRange('F67').setValue(copyValue3); //「目標入力シート」の目標③(C8)の内容を「入力シート」目標③欄(F7、F68)にコピーにコピー const copyValue4 = sh_temp2.getRange('C8').getValues(); console.log(copyValue4); sh_new.getRange('F7').setValue(copyValue4);  sh_new.getRange('F68').setValue(copyValue4); //「入力シート」の日付欄(U3)の指定準備_終了日の判定 //(条件1)「開始日」が月曜のとき「終了日」は4日後をセット if (openDayN ==1) { closeDate =new Date(openDate.setDate(openDate.getDate() + 4)); const c = Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AD3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AD64').setValue(c + closeDay); //(条件2)火曜のとき「終了日」は3日後をセット }else if (openDayN ==2) { closeDate =new Date(openDate.setDate(openDate.getDate() + 3)); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件3)水曜のとき「終了日」は2日後をセット }else if (openDayN ==3) { closeDate =new Date(openDate.setDate(openDate.getDate() + 2)); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件4)木曜のとき「終了日」は1日後をセット }else if (openDayN ==2) { closeDate =new Date(openDate.setDate(openDate.getDate() + 1)); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件5)金曜のとき }else if (openDayN ==1) { closeDate =new Date(openDate.setDate(openDate.getDate())); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); //(条件6)それ以外のとき 当日日付をセット }else { closeDate =new Date(openDate.setDate(openDate.getDate())); const c =Utilities.formatDate(closeDate, 'Asia/Tokyo', 'yyyy年MM月dd日'); const closeDayN = closeDate.getDay() const closeDay = '(' + array[closeDayN] + ')'; const myDate = o2 + openDay + "~" + c + closeDay; console.log(o2 + openDay); console.log(myDate); sh_new.getRange('U3').setValue(o1 + openDay); sh_new.getRange('AE3').setValue(c + closeDay); sh_new.getRange('U64').setValue(o1 + openDay); sh_new.getRange('AE64').setValue(c + closeDay); } //「入力シート」のシート名編集 sh_new.setName(mySheetName); } //シート追加済のメッセージ2を表示 Browser.msgBox("今週分の入力シートを作成しました。内容を入力してください。"); }
退会済みユーザー

退会済みユーザー

2021/06/27 12:05 編集

> 最後の処理のBrowser.msgBoxで定義したポップアップMsgが表示されませんでした。(涙)別のGASでは、同じコード記載で想定通りにポップアップMsgが表示されていたのですが、今回は表示されません。又、すでに同名のシートがファイル内に存在している場合にエラーとし、ポップアップ表示させたくて、下のコードを記載したのですがココもうまくmsg表示がされません。 質問の追加、ということで理解しました。 少なくとも if (ss.getSheetByName("mySheetName") != null) { ↓ if (ss.getSheetByName(mySheetName) != null) { 残りについては中身を見たうえで回答を修正しますので、しばらくお待ちください。
donguriko

2021/06/27 11:58

お手数をおかけしてまして本当に申し訳ありません!!
退会済みユーザー

退会済みユーザー

2021/06/27 12:09

後半にコード全体を追記しました。
donguriko

2021/06/27 13:23

qnoirさま お忙しい中、修正版コードありがとうございました。お手を煩わせてしまい申し訳ありませんでした。 ポップアップMsg表示されました。 (感謝) もっと勉強しないとですね。 大変助かりました。本当にありがとうございました!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問