Dim prevSelectedRow As Integer
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim c As Range
Dim ws As Worksheet, licenteSheet As Worksheet
Set ws = Me
Set licenteSheet = ThisWorkbook.Sheets(“Licente”)
Dim decision As String
’ Check if the row in “Licente” corresponding to the selected row has “DA” or “NU”
If Target.row <= licenteSheet.Cells(licenteSheet.Rows.Count, “C”).End(xlUp).row Then
decision = licenteSheet.Cells(Target.row, “C”).value
Else
decision = “”
End If
Dim colorForXCells As Long
If decision = “DA” Then
colorForXCells = RGB(0, 255, 0) ’ Green
ElseIf decision = “NU” Then
colorForXCells = RGB(255, 0, 0) ’ Red
Else
colorForXCells = RGB(255, 255, 255) ’ White or another default color
End If
Dim countX As Long ’ Initialize the counter for “X”
countX = 0
If Not Intersect(Target, ws.Rows(Target.row)) Is Nothing Then
’ Reset all cells in the row to white first
Target.EntireRow.Interior.Color = RGB(255, 255, 255)
’ Iterate only through cells within the target row
For Each c In Target.Cells
’ Color only the cells with “X” as per the decision and increment countX
If UCase(c.value) = “X” Then
c.Interior.Color = colorForXCells
countX = countX + 1 ’ Increment the counter for each “X” found
End If
Next c
’ Color the first cell and cell in column C of the selected row as per the decision
Target.Cells(1, 1).Interior.Color = colorForXCells ’ First cell in the row
ws.Cells(Target.row, 3).Interior.Color = colorForXCells ’ Cell in column C
prevSelectedRow = Target.row
End If
’ Update cell A1 with the count of ‘X’ cells found in the selected row
ws.Range(“A1”).value = countX
End Sub
to this code i want that empty cells on selected row to colored on yellowon select row