1
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?

スプレッドシート ボタンを押すとマクロを動作させる

Posted at

はじめに

スプレッドシート上にボタンを配置して、ボタンを押すとマクロを動くようにします。

ボタンを配置する

まずはスプレッドシートを開き、ボタンを作成します。挿入図形描画

image.png

てきとうなボタンを作成して、スクリプトを割り当てます。

image.png

image.png

拡張機能Apps Scriptにて、ボタンを押した時の動作を作成します。

マクロ.gs
function MyFunction() {
  var sheet = SpreadsheetApp.getActive();
  var activeRange = sheet.getActiveRange();

  if (activeRange.getNumRows() === 1 && activeRange.getNumColumns() === 1) {
    // アクティブなセルが1つの場合
    var activeCell = activeRange.getCell(1, 1);
    var nextCell = activeCell.offset(0, 1);
    nextCell.setValue("新しいテキスト");
  } else {
    // 複数のセルが範囲指定されている場合
    Browser.msgBox("複数のセルが選択されています。単一のセルを選択してください。");
  }
};

問題なければボタンを押すとマクロが動作します。

image.png

1
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
1
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?