3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Spreadsheet のセルから「ファイル名」「シート名」を取得する

Posted at

はじめに

Spreadsheet のセルから「ファイル名」、「シート名」を取得出来るようにします。
デフォルトの関数には無いので GAS で関数自作します。
コピペで行けます!怖くないよ!

手順

  • スプレッドシートを開く
  • 「拡張機能」→「Apps Script」でスクリプトエディタを開く
  • 以下コピペし保存
// スプレッドシートのファイル名を取得
function GET_FILE_NAME()
{
  return SpreadsheetApp.getActiveSpreadsheet().getName();
}

// スプレッドシートのシート名を取得
function GET_SHEET_NAME()
{
  return SpreadsheetApp.getActiveSpreadsheet().getSheetName();
}
  • スプレッドシートに戻る
  • セルに以下入力で「ファイル名」取得
=GET_FILE_NAME()
  • セルに以下入力で「シート名」取得
=GET_SHEET_NAME()

スクリーンショット

「拡張機能」→「Apps Script」でスクリプトエディタを開く

image.png

スクリプトエディタでコピペ

image.png

スプレッドシート上での取得結果

image.png

実際の僕の使いたかった状況

  • やりたいこと
    • ファイル名を「XXデータ_202301」等月毎に作成し、各ファイルへは直近1年分のデータが突っ込まれているが、毎月「最新月の情報」をまとめたい
  • 本件対応前
    • 「最新月の情報」まとめ時、その月の数字を手動入力しフィルタする
  • 本件対応後
    • 「最新月の情報」まとめ時、ファイル名の「202301」等からその月の数字を自動で取得し、フィルタ条件にしてまとめ作成

#シート名も似たような感じなので略

参考

Google Apps Script Spreadsheet Reference

Google スプレッドシートの関数リスト

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?