![Kくん](https://itmamalog.com/wp-content/uploads/2021/05/boy_06.png)
Kくん
シートの内容は一緒なんだけど、シート名をかえて複製する簡単な方法ないかな。
![](https://itmamalog.com/wp-content/uploads/2024/02/image-3-1024x378.png)
![ママ](https://itmamalog.com/wp-content/uploads/2021/05/youngwoman_37.png)
ママ
GASを使う方法ならあるわ。順番に説明するわね。
前準備
「定義」シートを作成(各シートにつけたい名前を記載)
![ママ](https://itmamalog.com/wp-content/uploads/2021/05/youngwoman_37.png)
ママ
「定義」のシートを作成して、
作成したいシート名をA列に記載してね
![](https://itmamalog.com/wp-content/uploads/2024/02/image-4.png)
ひな形を作成
![ママ](https://itmamalog.com/wp-content/uploads/2021/05/youngwoman_37.png)
ママ
全シート共通で使うところを作成してね
![](https://itmamalog.com/wp-content/uploads/2024/02/image-5.png)
GASの入力
1)[拡張機能]ー[Apps Script]をクリックする
![](https://itmamalog.com/wp-content/uploads/2024/02/image-6.png)
2)コード.gsに、以下のコードを貼り付ける
![](https://itmamalog.com/wp-content/uploads/2024/02/image-7-1024x277.png)
![ママ](https://itmamalog.com/wp-content/uploads/2021/05/youngwoman_37.png)
ママ
以下のコードの「★変更する★」のところに、【シート名:定義】で記載した、シート名の範囲を記載する。例:A2:A13
function copySheet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('定義');
var sheetCopy = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('ひな形');
var cell = sheet.getRange('★変更する★');
var cellValues = cell.getValues();
for (var i = 0; i < cellValues.length; i++) {
var sheetName = cellValues[i][0];
sheetCopy.copyTo(SpreadsheetApp.getActiveSpreadsheet()).setName(sheetName);
}
}
3)[実行]をクリック
※「承認が必要です」が表示された場合、こちらを参考にしてね。
![](https://itmamalog.com/wp-content/uploads/2024/02/image-2.png)
4)実行ログが、「実行完了」となったら、シートが複製されていることを確認。
![](https://itmamalog.com/wp-content/uploads/2024/02/image-8.png)
![](https://www16.a8.net/0.gif?a8mat=3Z77OX+1QIK2I+51W2+62U35)
コメント