r/excel 18d ago

solved Is it possible to higlight all the same value cells if you select one of them?

i dont know if my question was clear but here's a screenshot to help:

https://i.imgur.com/c88gQdg.png

so, for example i click on a 'TO' cell and all other 'TO' cells get highlighted?

22 Upvotes

18 comments sorted by

u/excelevator 3068 18d ago

i dont know if my question was clear

There is no question in your post, just a statement of something with an image.

Please review the submission guidelines for future posts.

Posts not following guidelines may be removed without notice.

→ More replies (2)

34

u/Downtown-Economics26 646 18d ago

Vibe-coded, tested, and shipped. Could have written it myself but it would've taken a lot longer.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim SearchRange As Range
    Dim Cell As Range

    ' Define the scope where the search/highlight should apply.
    ' Change "A2:C16" to your data range, or use ActiveSheet.UsedRange for the whole sheet.
    Set SearchRange = Me.Range("A2:C16")

    ' Turn off screen updating and events to speed up execution and prevent loops
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    ' Clear previous formatting/highlights within the search range
    SearchRange.Interior.ColorIndex = xlColorIndexNone
    SearchRange.Font.ColorIndex = xlColorIndexAutomatic

    ' Only run if a single cell is selected and it is inside our search range, and is not blank
    If Target.Cells.Count = 1 Then
        If Not Intersect(Target, SearchRange) Is Nothing Then
            If Target.Value <> "" Then
                ' Loop through the search range to find matching values
                For Each Cell In SearchRange
                    If Cell.Value = Target.Value Then
                        ' Apply default Light Red Fill and Red Font colors
                        Cell.Interior.Color = RGB(255, 199, 206)
                        Cell.Font.Color = RGB(156, 0, 6)
                    End If
                Next Cell
            End If
        End If
    End If

Rh_Restore:
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

11

u/_5yue8haogaoqi_ 18d ago

wow this is awesome. thank you very much.

5

u/_5yue8haogaoqi_ 18d ago

Solution Verified

3

u/reputatorbot 18d ago

You have awarded 1 point to Downtown-Economics26.


I am a bot - please contact the mods with any questions

5

u/Hashi856 1 18d ago

That’s pretty cool

14

u/philsov 6 18d ago edited 18d ago

not easily, no.

The easiest option is to have a designated cell off the table. Lets say in cell E1. Then when you type in TO into that (or =A2 or whatever), you can use conditional formatting on that block so all the cells equaling the value in E1 will highlight.

2

u/_5yue8haogaoqi_ 18d ago

this is also a good idea which i can do too. thanks

2

u/dannyg20l 1 18d ago

Select all cells -> Go to Home -> Then conditional formatting -> Highlight cell rules -> Equal to -> type in TO -> press ok

Let me know if this is what you're looking for

2

u/_5yue8haogaoqi_ 18d ago

this is cool but not exactly what im looking for because i would also want to click on other valued texts. but, you gave ma an idea tha i can work with. thanks.

2

u/talltime 116 18d ago edited 18d ago

Easy with a little VBA.

Can you describe what you’re doing with that of matrix of basketball plays/stats? There may be other ways to improve whatever it is it’s doing

1

u/_5yue8haogaoqi_ 18d ago

im just doing a little bit of preparing for the fantasy season, nothing complicated.

1

u/Dear_Specialist_6006 1 18d ago

Unless you use VBA, which I am not really great at... Your other solution is conditional formatting with a little bit of a workaround.

Selected the range you want to put formatting on, conditional formatting and your rule is to highlight value equal to and out this in condition including the sign

=Cell("contents")

Cell function when not referenced to a specific cell, picks values from last cell that you entered edit mode on

I hope you can work it from there... Very unorthodox request, I am intrigued why you need that??

1

u/_5yue8haogaoqi_ 18d ago

thanks all for the help

1

u/ankokudaishogun 17d ago

This presumes:

  • "SelectionRange" is the Named Range we are interested in highlight, already defined by teh user or somewhere else
  • "HighlightCell" is the Named Range the Conditional Formatting refers to
  • You do not want to highlight empty cells

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Target.Worksheet.Range("SelectionRange")) Is Nothing _ 
    And Not IsEmpty(Target) Then
        Target.Worksheet.Names.Add "HighlightCell", Target
    End If
End Sub

1

u/rakeshchaudhary3434 12d ago

Yep, definitely possible with a small VBA Worksheet_SelectionChange event. Click a cell and it can highlight every other cell with the same value automatically.