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

Excelで指定されたセル値に基づいて特定の形状を非表示または再表示するにはどうすればよいですか?

実際には、特定のセルの値に基づいて、特定の形状を非表示または非表示にすることができます。 次の方法が役立ちます。

VBAコードで指定されたセル値に基づいて特定の形状を非表示または再表示します


VBAコードで指定されたセル値に基づいて特定の形状を非表示または再表示します

たとえば、セルA1に数値1を入力するときに特定の形状を再表示したり、セルA1が他の値の場合はこの形状を非表示にしたりします。 これを実現するには、次のVBAコードを実行してください。

1.非表示または再表示する図形が含まれているシートタブを右クリックし、[ コードを表示 右クリックメニューから。

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

VBAコード:指定されたセル値に基づいて特定の形状を非表示または再表示します

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row = 1 And Target.Column = 1 Then _
        Me.Shapes("Oval 6").Visible = (Cells(1, 1).Value = 1)
End Sub

ノート:コード内:

1) 行= 1 & 列= 1 行1と列1にある特定のセルを示します。Cells(1、XNUMX)は対応するセルAXNUMXです。
2) 値= 1、数値1は、形状を表示する特定の値です。
3) "オーバル6」は特定の形状の名前です。

必要に応じて変更できます。

3。 プレス 他の + Q キーを同時に閉じて アプリケーション向け Microsoft Visual Basic 窓。

これ以降、セルA1に番号1を入力すると、「楕円形6」の形状が非表示になります。 ただし、セルA2に数値1などの他の値を入力すると、「楕円形6」の形状がすぐに非表示になります。


関連記事:

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

🤖 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 (14)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello,

thank you for making this guide!

I have one question:
If i need a shape to show up based on two or more values, how is this done?
This comment was minimized by the moderator on the site
Hi Kasper Pedersen,

Suppose you want to show up a shape named "Oval 4" when both cells A1 and C8 contain the specified values (1 and 2 respectively), and if either of the cells is cleared (i.e., its value becomes empty), the shape will set to invisible. You can try the following VBA code to get it done.

Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("A1").Value = 1 And Range("C8").Value = 2 Then
        Me.Shapes("Oval 4").Visible = True
    ElseIf Range("A1").Value = "" Or Range("C8").Value = "" Then
        Me.Shapes("Oval 4").Visible = False
    End If
End Sub
This comment was minimized by the moderator on the site
Thanks, but i want the shape not to be visible if the value is diffrent than "1" and "2" as shown in your example. eg. if the value is diffrent from 1 in cell A1 the shape becomes invisible. Is it possible?
This comment was minimized by the moderator on the site
This article doesn't give any hint as to how one gets the name of a shape.

I have checked the name manager and the object manager in VBA as well as the context menu - there is no "Properties" menu for shapes.

So, where is the shape name?
This comment was minimized by the moderator on the site
Hi Cornan,
The shape name will be displayed on the Name box of worksheet when selecting the shape. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
2 questions:

1. I cant seem to get this code to run and i dont understand why... copied and pasted it exactly as it is there...help!!!


2. how do i change it for shapes like Shapes.Range(Array("Rounded Rectangle 1"))
This comment was minimized by the moderator on the site
Hi Gus,
You must miss something in the operation.
Supposing your shape name is "Rounded Rectangle 1", please copy the below code into the worksheet code window (this worksheet should contain the specified shape "Rounded Rectangle 1").
From now on, only typing number 1 into A1 cell can display the shape "Rounded Rectangle 1". If you type in other content, the shape will be hidden.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 And Target.Column = 1 Then _
Me.Shapes("Rounded Rectangle 1").Visible = (Cells(1, 1).Value = 1)
End Sub
This comment was minimized by the moderator on the site
You left out the ":"
This comment was minimized by the moderator on the site
I am a newbie in VBA Excel. I am working with this code and I would like to optimize it. This code makes a shape visible on an active cell if value is 1 other values hide it. Range includes J13:AC161. If I will use the code below, it will take me more lines of code. Any help will be much appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Range("E13").Value = 1 Then
ActiveSheet.Shapes("rt1").Visible = True
Else
ActiveSheet.Shapes("rt1").Visible = False
End If

If ActiveSheet.Range("F13").Value = 1 Then
ActiveSheet.Shapes("rt2").Visible = True
Else
ActiveSheet.Shapes("rt2").Visible = False
End If

If ActiveSheet.Range("G13").Value = 1 Then
ActiveSheet.Shapes("rt3").Visible = True
Else
ActiveSheet.Shapes("rt3").Visible = False
End If

If ActiveSheet.Range("H13").Value = 1 Then
ActiveSheet.Shapes("rt4").Visible = True
Else
ActiveSheet.Shapes("rt4").Visible = False
End If

If ActiveSheet.Range("I13").Value = 1 Then
ActiveSheet.Shapes("rt5").Visible = True
Else
ActiveSheet.Shapes("rt5").Visible = False
End If

If ActiveSheet.Range("J13").Value = 1 Then
ActiveSheet.Shapes("rt6").Visible = True
Else
ActiveSheet.Shapes("rt6").Visible = False
End If
...

End Sub
This comment was minimized by the moderator on the site
Good day,
Do you mean you want to display or hide lots of specified shapes based on cells in range J13:AC161 with brief code?
This comment was minimized by the moderator on the site
This works great for me as long as the value entered is a number. I need it to work on letters like A B C etc: when i use letters it works backwards enter A and it hides i need it to be visible when i enter a letter any ideas
This comment was minimized by the moderator on the site
You can use letters instead, you just need to add " to either side. E.g. Me.Shapes("Oval 6").Visible = (Cells(1, 1).Value = "A")
This comment was minimized by the moderator on the site
How about if i want to add two values as the input such as : E.g. Me.Shapes("Oval 6").Visible = (Cells(1, 1).Value = "A" Or "B")?
This comment was minimized by the moderator on the site
Me.Shapes("Rounded Rectangle 2").Visible = (Cells(1, 1).Value = "A" Or Cells(1, 1).Value = "B")
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations