Dim prevSelectedRow As Integer Private Sub Worksheet_SelectionChange(ByVal Target As…
- User
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 Dim colorForEmptyCells As Long colorForEmptyCells = RGB(0, 0, 255) ' Blue for empty cells 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 to remove previous formatting Target.EntireRow.Interior.Color = RGB(255, 255, 255) ' Iterate only through cells within the target row For Each c In Target.Cells If UCase(c.value) = "X" Then c.Interior.Color = colorForXCells countX = countX + 1 ' Increment the counter for each "X" found ElseIf c.value = "" Then c.Interior.Color = colorForEmptyCells ' Color empty cells blue 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 = countXEnd Sub
for this code change colour of empty cell to yellow and hide rows before selected row automaticaly
- Assistant
- User
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 Dim colorForEmptyCells As Long colorForEmptyCells = RGB(0, 0, 255) ’ Blue for empty cells
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
- Assistant