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 countX As Long ' Variable to count cells containing "X" countX = 0 ' Initialize counter to zero for each new selection ' Assuming column C in "Licente" sheet holds "DA" or "NU" for the corresponding rows in this sheet Dim decision As String If Target.row <= licenteSheet.Cells(Rows.Count, "C").End(xlUp).row Then decision = licenteSheet.Cells(Target.row, "C").value Else decision = "" End If ' Handle cell coloring based on 'DA' or 'NU' Dim colorForXCells As Long Dim colorForFirstCell As Long If decision = "DA" Then colorForXCells = RGB(0, 255, 0) ' Green colorForFirstCell = RGB(0, 255, 0) ElseIf decision = "NU" Then colorForXCells = RGB(255, 0, 0) ' Red colorForFirstCell = RGB(255, 0, 0) Else colorForXCells = RGB(255, 255, 255) ' White, or another default color colorForFirstCell = RGB(255, 255, 255) End If If Target.Cells.Count = ws.Columns.Count Then For Each c In Target.Rows.Cells If UCase(c.value) = "X" Then c.Interior.Color = colorForXCells countX = countX + 1 ' Increment the counter for each "X" found Else c.Interior.Color = RGB(255, 255, 255) ' Reset non-X cells to white End If Next c ' Color the first cell in the selected row according to DA or NU decision Target.Cells(1, 1).Interior.Color = colorForFirstCell 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 i want that the colour of c cell on the selected row to change his colour acordig to value DA or NU .
- Assistant
- User
Iit change all cells from selected row accordind from c value , i want only cells with an x mark inside , first cell from selected row and cell c with the same colour acorging to c value rest cells must be be white
- Assistant
- User
its not showing number of cells wint an x inside on sleceted row on cel a1
- Assistant
Apologies for missing that part. Let’s incorporate the counting and updating of the total number of cells with an "X" inside the selected row into cell A1. Here is the revised code which includes the counting of "X" marks as well and displays the count in cell A1 of the worksheet:
- User
ok to this code i want to add this - on the end to hide automaticaly rows before selected row except row1 on deselect unhide all rows
- Assistant
- User
unhide all rows after deselcting
- Assistant