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

Excelでセルをダブルクリックしたときに、指定した行または列を非表示または再表示するにはどうすればよいですか?

通常、行と列は、右クリックしてコンテキストメニューから[非表示]または[再表示]オプションを選択することで、非表示または表示できます。 この記事では、Excelのセルをダブルクリックして、指定した行または列をすばやく非表示または表示する方法について説明します。

VBAコードでセルをダブルクリックするときに、指定した行または列を非表示または再表示します


VBAコードでセルをダブルクリックするときに、指定した行または列を非表示または再表示します

次のVBAコードは、特定のセルをダブルクリックすることで、ワークシート内の指定された行または列をすばやく非表示または再表示するのに役立ちます。 次のようにしてください。

1.行または列を非表示にするワークシートを開きます。 シートタブを右クリックして、 コードを表示 コンテキストメニューから選択します。

2.オープニングで アプリケーション向け Microsoft Visual Basic ウィンドウの場合は、次のVBAコードをコードウィンドウにコピーしてください。

VBA:ワークシートのセルをダブルクリックして、指定した行を非表示/再表示します。

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby20171226
    Dim xRgHidden As Range
    If (Not Intersect(Target, Range("A1:A4")) Is Nothing) And (Target.Count = 1) Then
        Set xRgHidden = Range("10:13")
        xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
    End If
End Sub

VBA: ワークシート内のセルをダブルクリックして、指定した列を非表示/再表示します。

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby20171226
    Dim xRgHidden As Range
    If (Not Intersect(Target, Range("A1:A4")) Is Nothing) And (Target.Count = 1) Then
        Set xRgHidden = Range("D:E")
        xRgHidden.EntireColumn.Hidden = Not xRgHidden.EntireColumn.Hidden
    End If
End Sub

Note:コードでは、 A1:A4, 10:13 & D:E A1:A4 の範囲の任意のセルをダブルクリックすると、行 10:13 または列 D:E が自動的に非表示になることを示します。

3。 プレス 他の + F11 を閉じるためのキー アプリケーション向け Microsoft Visual Basic 窓。

今後、範囲 A1:A4 のセルをダブルクリックすると、行 10:13 または列 D:E が自動的に非表示になります。 セルを再度ダブルクリックすると、非表示の行または列がすべてすぐに表示されます。


関連記事:

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

🤖 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 (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This helped a lot but i'm trying to do this but everything starts hidden and hide and unhide isolated cells rather than a range? thanks!
This comment was minimized by the moderator on the site
This is very cool and extremely helpful. However, I want to repeat the same code for different sets of rows to hide when clicking on different cells. How can I use the same code multiple times in one sheet so that the code name is not the same? Thank you!
This comment was minimized by the moderator on the site
Hi,If you want to hide different sets of rows when clicking on different cells, please try to modify the cells and row numbers in below code.The below code can achieve: when double clicking A1, the row "10:13" will be hidden; when double clicking A2, the row "15:20" will be hidden, and double clicking A3 will hide row "22:23". If you want to add more conditions, please copy the code lines from If to End If and modify the cells and row numbers as you need.<div data-tag="code">Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby20210409
Dim xRgHidden As Range
If (Not Intersect(Target, Range("A1")) Is Nothing) And (Target.Count = 1) Then
Set xRgHidden = Range("10:13")
xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
End If
If (Not Intersect(Target, Range("A2")) Is Nothing) And (Target.Count = 1) Then
Set xRgHidden = Range("15:20")
xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
End If
If (Not Intersect(Target, Range("A3")) Is Nothing) And (Target.Count = 1) Then
Set xRgHidden = Range("22:23")
xRgHidden.EntireRow.Hidden = Not xRgHidden.EntireRow.Hidden
End If
End Sub
This comment was minimized by the moderator on the site
This is so helpful! I'm wondering if their is anyway to be able to add additional 'hidden' rows over time without having to shift all the numbers in the code to make everything line up properly? Thanks so much!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations