Hi all,
I have very little coding expertise and have searched the web and the forum, but couldn't quite find the solution.
I am trying to show/hide hundreds of text boxes based on their values.
Use case:
I have an image of a map (jpg), which includes 222 locations. Each of these locations has a text box (simply placed on top of the image) to display the number of issues at this location. The issues per location are manually entered on a different sheet and are updated from time to time.
Each text box acts like a location label and is linked to the input cell, so it displays the respective cell value. The use case is to use the image with all text boxes in presentations. There is no need to interact with the boxes (other than display).
I am trying to hide the text box when a location has no issues (value: 0).
Whenever a cell value is changed (Range E4:E222), a macro should run and hide the boxes with no value.
My current code works (created from various posts I found), but I am trying to avoid entering this hundreds of times.
[Location_1] refers to the text box name. Theoretically I would have to create this 222 times, but surely there is a better way!?
Each text box is named after the real-world location to make identification easier. So, ideally, I can simply refer to a simple list of 222 names (by copy/paste) in the code. The list of locations very rarely changes, but could.
I hope this makes sense.
I appreciate your help!
I have very little coding expertise and have searched the web and the forum, but couldn't quite find the solution.
I am trying to show/hide hundreds of text boxes based on their values.
Use case:
I have an image of a map (jpg), which includes 222 locations. Each of these locations has a text box (simply placed on top of the image) to display the number of issues at this location. The issues per location are manually entered on a different sheet and are updated from time to time.
Each text box acts like a location label and is linked to the input cell, so it displays the respective cell value. The use case is to use the image with all text boxes in presentations. There is no need to interact with the boxes (other than display).
I am trying to hide the text box when a location has no issues (value: 0).
Whenever a cell value is changed (Range E4:E222), a macro should run and hide the boxes with no value.
My current code works (created from various posts I found), but I am trying to avoid entering this hundreds of times.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("E4:E225")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
If Range("E4") = 0 Then
ActiveSheet.Shapes.Range(Array("[LOCATION_1]")).Visible = msoFalse
Else
ActiveSheet.Shapes.Range(Array("[LOCATION_1]")).Visible = msoTrue
End If
End If
End Sub
[Location_1] refers to the text box name. Theoretically I would have to create this 222 times, but surely there is a better way!?
Each text box is named after the real-world location to make identification easier. So, ideally, I can simply refer to a simple list of 222 names (by copy/paste) in the code. The list of locations very rarely changes, but could.
I hope this makes sense.
I appreciate your help!