View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel
Earl Kiosterud Earl Kiosterud is offline
external usenet poster
 
Posts: 611
Default What's the best way to toggle between true and false in Excel? Hi all, My excel work involves a lot of toggling between true and false (boolean types) ... and it's very repetitive... Is there a way to select a bunch of cells, and press a key s

Luna,

Here's a sub you can invoke with a keyboard shortcut, and it'll toggle all the selected
cells with booleans (TRUE and FALSE). It leaves other values, including text and numbers
and formulas, alone. It can handle multiple-cell selections, including separate areas (Ctrl
key used to select non-contiguous cells). It leaves your right-click alone.

It has a shortcoming that it thinks 0 and -1 are FALSE and TRUE, and will toggle these
values (including formulas that return these values, replacing them with 0 or 1). I don't
remember where you test the type (boolean) of the contents of a a cell, if it's even
possible.

Sub ToggleBoolean()
Dim thing As Range
For Each thing In Selection
If thing = True Or thing = False Then ' is it boolean?
thing = Not thing
End If
Next thing
End Sub

You could put it in a module in your workbook (or in Personal.xls, if you want it available
for all workbooks), then assign a keyboard shortcut to run it (Tools - Macro - Macros -
Options).

When you bottom-post to a reply that's top-posted, it gets messy.
--
Regards from Virginia Beach,

Earl Kiosterud
www.smokeylake.com
-----------------------------------------------------------------------
"LunaMoon" wrote in message
...
What's the best way to toggle between true and false in Excel?

Hi all,

My excel work involves a lot of toggling between true and false
(boolean types) ... and it's very repetitive...

Is there a way to select a bunch of cells, and press a key short-cut
so that they toggle all at once?

Thanks!