Highlight cell based on values

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,514
Try this macro. I think that the value 34115 should be 3415.
Code:
Sub MatchVals()
    Application.ScreenUpdating = False
    Dim LastRow As Long, ws As Worksheet, rng As Range, x As Long, y As Long, val As String, fnd As Range
    For Each ws In Sheets
        LastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        For x = 14 To 38
            If x <> 26 Then
                For y = 2 To LastRow
                    For Each rng In ws.Range(ws.Cells(y, x), ws.Cells(y + 3, x))
                        val = val & rng
                    Next rng
                    Set fnd = ws.Range("AU1:BF1").Find(val, LookIn:=xlValues, lookat:=xlWhole)
                    If Not fnd Is Nothing Then
                        ws.Range(ws.Cells(y, x), ws.Cells(y + 3, x)).Interior.ColorIndex = 6
                    End If
                    val = ""
                Next y
            End If
        Next x
    Next ws
    Application.ScreenUpdating = True
End Sub
 

JAVEDR

New Member
Joined
Sep 17, 2019
Messages
14
I think that the value 34115 should be 3415, perfect it should be 3415 right.

I will check code let u know soon, thanks a ton for your valuable time.
 

JAVEDR

New Member
Joined
Sep 17, 2019
Messages
14
code is working perfect with 3415 this criteria (4 len), is it possible that it can work for more then 4 len or less than 4 len criteria too

thx
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,514
The macro will work with any length as long as the values in AU1:BF1 match the values you want to highlight.
 

JAVEDR

New Member
Joined
Sep 17, 2019
Messages
14
Hello sir,

Example in AU1 value is 34156 instead of 3415 rows are not getting highlight.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,514
Try changing
Code:
 xlWhole
to
Code:
xlPart
 

JAVEDR

New Member
Joined
Sep 17, 2019
Messages
14
thats perfect code thanks a lot its working for more than 4 numbers but not working for less than 4 numbers.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,514
If the numbers in "AU1:BF1" are less than 4 characters while the numbers in your data are always 4 characters then it's hard to get a match.
 

Forum statistics

Threads
1,081,986
Messages
5,362,560
Members
400,681
Latest member
mariscann

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top