Ctrl-Click to change TRUE and FALSE in a cell

A

andre.roukema

If you hold the control-key when you select a cell, then one area will be added to the current selection even if you control-click on the activecell.

This behaviour can be used to do something cool: ctrl-click on a cell to flip TRUE and FALSE. You can use the SheetSelectionChange event of the workbook to accomplish this.

Here is the code to insert in the code module of the workbook:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Areas.Count = 2 Then
If Target.Areas(2).Cells.Count = 1 Then
If TypeName(Target.Areas(2).Value) = "Boolean" Then
Target.Areas(2).Value = Not Target.Areas(2).Value
Target.Areas(2).Select
End If
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top