Apont
Apont
Dim ws As Worksheet
Dim tbl As ListObject
Dim rng As Range
Dim tblRng1 As Range
Dim tblRng2 As Range
Dim cell As Range
Dim lastColumn As Long
Call ConditionalFormatting
CleanExit:
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
HandleError:
MsgBox "Error: " & Err.Description
Resume CleanExit
End Sub
' Add conditional formatting for blank cells within the table
Set tblFm = rng.FormatConditions.Add(xlBlanksCondition)
tblFm.Interior.Color = COLOR_YELLOW ' Yellow for blanks
End Sub
Private Sub ResetCellFormatting(ByRef cell As Range)
cell.Interior.ColorIndex = COLOR_RESET
End Sub
inputValue = LCase(Trim(cell.Value))
' Define the range for the row above the table (dynamic row based on table's
starting row)
If tableRow > 1 Then ' Ensure there's a row above the table to format
Set headerRange = ws.Range(ws.Cells(tableRow - 1, 1), ws.Cells(tableRow -
1, lastColumn))
.HorizontalAlignment = xlCenterAcrossSelection
.VerticalAlignment = xlCenter
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThick
.Color = RGB(9, 68, 155)
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThick
.Color = RGB(9, 68, 155)
End With
End With
Else
MsgBox "No row above the table to format."
End If
End Sub
' Get the table's range (including header and body, but excluding totals)
Set tblRange = tbl.Range
Set rng = tbl.DataBodyRange
' Remove any existing highlights in the table (clear conditional formatting
or background color)
tblRange.Interior.ColorIndex = xlNone
tblRange.Font.Color = RGB(0, 0, 0)
Call AddCellConditionalFormatting(tblRng2)
' Highlight the entire row for the selected cell if within the table's body
range
If Not Intersect(Target, tbl.DataBodyRange) Is Nothing Then
Set selectedRow = tbl.ListRows(Target.Row - tbl.DataBodyRange.Cells(1,
1).Row + 1).Range
selectedRow.FormatConditions.Delete
selectedRow.Interior.Color = 12611584
selectedRow.Font.Color = RGB(255, 255, 255)
End If
Else
' Clear formatting if the selection is outside the table
tblRange.Interior.ColorIndex = xlNone
tblRange.Font.Color = RGB(0, 0, 0)
Call AddCellConditionalFormatting(tblRng2)
End If
End Sub