メインコンテンツへスキップ

Excelのワークシートにコマンドボタンを常に表示するにはどうすればよいですか?

場合によっては、ワークシートを上下にスクロールする方法に関係なく、ワークシートを移動し続けるためにフローティングコマンドボタン(ActiveXコントロール)が必要になることがあります。 この記事では、それを実現する方法を紹介します。

VBAコードを使用してワークシートにコマンドボタンを常に表示する


VBAコードを使用してワークシートにコマンドボタンを常に表示する

コマンドボタンを常にワークシートに表示するには、次のようにしてください。

1.フローティングにするActiveXコントロールコマンドボタンを含むワークシートで、シートタブを右クリックし、[ コードを表示 コンテキストメニューから選択します。

2.ポップアップで アプリケーション向け Microsoft Visual Basic ウィンドウで、以下のVBAコードをコピーしてコードウィンドウに貼り付けます。

VBAコード:コマンドボタンを常にワークシートに表示する

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        On Error GoTo 0
        With Cells(Windows(1).ScrollRow, Windows(1).ScrollColumn)
            CommandButton1.Top = .Top + 100
            CommandButton1.Left = .Left + 300
        End With
End Sub

Note:abovdeコードでは、CommandButton1は常に表示したいボタン名です。 必要に応じて変更してください。

3。 次に、 他の + Q 終了するためのキー アプリケーション向け Microsoft Visual Basic 窓。

これ以降、コマンドボタンは常にワークシートの上部中央に表示され、下のスクリーンショットに示すように、アクティブなクリックされたセルが移動します。

Note:このVBAは、ActiveX制御コマンドボタンに対してのみ機能します。


関連記事:

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
it works fine in one workbook, now i tried to do the same thing in another workbook and i got a compiling error because of the selectionchange. i'm pretty new in vba - maybe it's because i already got a private sub worksheet_selectionchange? do you know how i can fix this? 
This comment was minimized by the moderator on the site
I think it should specify that the button has to be an ActiveX one to the code work. ^.^'
This comment was minimized by the moderator on the site
Hi,
Thank you for your reminder.
This comment was minimized by the moderator on the site
I think it should specify that the button has to be an ActiveX one to the code work. ^.^'
This comment was minimized by the moderator on the site
Does not work :-(
This comment was minimized by the moderator on the site
Hi,
When you scrolling down the worksheet, please click to change the active cell to the visible area to make it work. Thank you for your comment.
This comment was minimized by the moderator on the site
see it, not working, i'm scrolling down and also command button down, i want to fix on the top of right side of sheet.
This comment was minimized by the moderator on the site
Hi,
When you scrolling down the worksheet, please click to change the active cell to the visible area to make it work. Thank you for your comment.
This comment was minimized by the moderator on the site
not working
This comment was minimized by the moderator on the site
Thanks a lot ... It worked...
This comment was minimized by the moderator on the site
Works fine for me. Thx
This comment was minimized by the moderator on the site
Thanks its good with cellselecting
This comment was minimized by the moderator on the site
Not good QA - check your name on the button. If this is what gets published for the Web community to see, what goes in behind the scenes with the code? :-)
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations