Want to highlight cell based on intersection row and column vba excel

elkaa

New Member
Joined
Sep 14, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi members.

I'm looking for a formula / vba code of finding the intersection between a column and a line.
I have 2 values from another sheet that i need to match them with row and column head on another sheet and intersection need to be highlighted.
would be great if someone can help me with it.
thankyou so much
 

Attachments

  • Screenshot 2021-09-14 144545.png
    Screenshot 2021-09-14 144545.png
    46.3 KB · Views: 15
  • Screenshot 2021-09-14 144635.png
    Screenshot 2021-09-14 144635.png
    43.2 KB · Views: 15

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Mr Excel Playground 3.xlsm
ABCDEFGHIJK
112hihiholokoiopo
245ho45
325lo45
454ko45
512io22
622po12
725
816
916
1016
1145
1245
1345
Sheet24
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F2:K13Expression=IF(ISERROR(MATCH(F$1&"-"&$E2,$B$1:$B$6&"-"&$A$1:$A$6,0)),FALSE,TRUE)textNO
 
Upvote 0
thank you for the help i don't want to use conditional formatting if i can have vba code or formula would be grate thank you
 
Upvote 0
I find VBA tedious. How would you like it highlighted in a formula?
 
Upvote 0
Upvote 0
Public Function GetTableVal(ByVal tblName As String, ByVal rowName As String, ByVal colName As String) As Boolean

On Error Resume Next
Dim rng As Range
Set rng = Range(tblName)
On Error GoTo 0

If rng Is Nothing Then
GetTableVal = "ERROR: Table not found"
Exit Function
End If

Dim tbl As ListObject
Set tbl = rng.ListObject

On Error Resume Next
Dim colIndex As Long
colIndex = tbl.ListColumns(colName).Index
On Error GoTo 0

If colIndex = 0 Then
GetTableVal = "ERROR: Column not found"
Exit Function
End If

Dim rowIndexRange As Range
Set rowIndexRange = tbl.ListColumns(4).Range.Find(rowName, LookIn:=xlValues, LookAt:=xlWhole)

If rowIndexRange Is Nothing Then
GetTableVal = "ERROR: Row not found"
Exit Function
End If

Dim rowIndex As Long
rowIndex = rowIndexRange.Row - tbl.Range.Row + 1

Dim res As Range
Set res = tbl.Range(rowIndex, colIndex)
res.Interior.ColorIndex = 55

GetTableVal = True

End Function

found this code but it's to get value from intersection between row and colonne i wanted to change it to colore the cell but it's didn't work when i try to use interor.colorIndex on res nothing is done.if somone can tel me why i will be thankful
 
Upvote 0
Mr Excel Playground 3.xlsm
ABCDEFGHIJK
112hihiholokoiopo
245ho45
325lo45
454ko45
512io22
622po12
725
816
916
1016
1145
1245
1345
Sheet24
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F2:K13Expression=IF(ISERROR(MATCH(F$1&"-"&$E2,$B$1:$B$6&"-"&$A$1:$A$6,0)),FALSE,TRUE)textNO
Hello, can this be modified to only search B1 then A1, not $B$1:$B$6&"-"&$A$1:$A$6. I have tried $B$1&"-"&$A$1, and that didn't work?
 
Upvote 0
VBA option, please try it on a copy of your workbook (change the sheet names to suit).
VBA Code:
Option Explicit
Sub elkaa()
    Application.ScreenUpdating = False
    Dim ws1 As Worksheet, ws2 As Worksheet, a
    Set ws1 = Worksheets("Sheet1")          '<-- *** Change the sheet names to suit ***
    Set ws2 = Worksheets("Sheet2")
    With ws1.Range("A1", ws1.Cells(Rows.Count, "A").End(xlUp))
        a = Evaluate(.Address(, , , 1) & "&""|""&" & .Offset(, 1).Address(, , , 1))
    End With
    
    Dim LRow As Long, LCol As Long, i As Long, j As Long, s As String
    LRow = ws2.Cells(Rows.Count, "A").End(xlUp).Row
    LCol = ws2.Cells(1, Columns.Count).End(xlToLeft).Column
    ws2.Range(ws2.Cells(2, 2), ws2.Cells(LRow, LCol)).ClearFormats
    
    With ws2
        For i = 2 To LRow
            For j = 2 To LCol
                s = .Cells(i, 1) & "|" & .Cells(1, j)
                If Not IsError(Application.Match(s, a, 0)) Then
                    .Cells(i, j).Interior.Color = vbRed
                End If
            Next j
        Next i
    End With
    Application.ScreenUpdating = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top