I have an addin that uses SheetSelectionChange event to highlight the entire row and column in a sheet when I click on a cell. I would like the option to turn the highlighting on/off by selecting a checkbox. I added a checkbox by customizing the ribbon, and I have code that passes the value of the CheckBox pressed state into my SheetSelectionChange event, but the toggle on/off is not working. The highlighting either stays on the pressed state that exists when I open the sheet, and it won't change. Below is the code I have.
Code in ThisWorkBook:
Code in Module1:
XML for Checkbox:
Thank you for helping with this.
Code in ThisWorkBook:
Code:
Public WithEvents App As Application
Public Sub App_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If CheckBoxResult = True Then
Application.ScreenUpdating = False
' Clear the color of all the cells
Cells.Interior.ColorIndex = 0
With Target
' Highlight the entire row and column that contain the active cell
.EntireRow.Interior.Color = RGB(250, 250, 250)
.EntireColumn.Interior.Color = RGB(250, 250, 250)
End With
Application.ScreenUpdating = True
End If
End Sub
Private Sub Workbook_Open()
Set App = Application
End Sub
Code in Module1:
Code:
Public CheckBoxResult As Boolean
Function CheckBoxAction(control As IRibbonControl, pressed As Boolean)
If pressed = True Then
CheckBoxResult = True
End If
End Function
XML for Checkbox:
Code:
<customUI xmlns="[URL]http://schemas.microsoft.com/office/2006/01/customui[/URL]">
<ribbon>
<tabs>
<tab idMso="TabHome">
<group idMso="GroupFont" visible="false" />
</tab>
<tab id="CustomTab" label="UTILITIES">
<group id="HighlightRowColumn" label="HighlightRowColumn">
<checkBox id="CheckBox1" label="Highlight On/Off"
screentip="This is a check box"
onAction="CheckBoxAction" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Thank you for helping with this.