doreilly2409
New Member
- Joined
- Aug 31, 2023
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi
I am running a code which creates a red circle over a cell when a condition is met ("yes" appears in the cell). The problem is the cell, in Column I, is controlled by a drop down being selected in a corresponding cell in column D. The loop continues to run when any cell in the work sheet is clicked meaning multiple red circles are placed, one on top of the other.
I want the code to be constantly running but only create the circle once. I know its something to do with events being updated etc but I can't quite crack it. Any help would be greatly welcomed. Please see my code below
Thanks
Dan
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Dim cell As Range
Dim searchText As String
Dim shp As Shape
Set ws = ThisWorkbook.Sheets("Heat Map")
searchText = "yes"
For Each cell In ActiveSheet.Range("i9:i28")
If InStr(1, cell.Value, searchText, vbTextCompare) > 0 Then
Set shp = ws.Shapes.AddShape(msoShapeOval, cell.Left, cell.Top, cell.Width, cell.Height)
With shp
.Line.ForeColor.RGB = RGB(255, 0, 0)
.Line.Weight = 1
.Fill.Transparency = 1
End With
End If
Next cell
End Sub
I am running a code which creates a red circle over a cell when a condition is met ("yes" appears in the cell). The problem is the cell, in Column I, is controlled by a drop down being selected in a corresponding cell in column D. The loop continues to run when any cell in the work sheet is clicked meaning multiple red circles are placed, one on top of the other.
I want the code to be constantly running but only create the circle once. I know its something to do with events being updated etc but I can't quite crack it. Any help would be greatly welcomed. Please see my code below
Thanks
Dan
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Dim cell As Range
Dim searchText As String
Dim shp As Shape
Set ws = ThisWorkbook.Sheets("Heat Map")
searchText = "yes"
For Each cell In ActiveSheet.Range("i9:i28")
If InStr(1, cell.Value, searchText, vbTextCompare) > 0 Then
Set shp = ws.Shapes.AddShape(msoShapeOval, cell.Left, cell.Top, cell.Width, cell.Height)
With shp
.Line.ForeColor.RGB = RGB(255, 0, 0)
.Line.Weight = 1
.Fill.Transparency = 1
End With
End If
Next cell
End Sub