Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Toggle a cell

I've tried several methods but can't quite figure it out. How can I write
the code so that when I click on a cell within a column it will toggle it
(i.e. if blank, put an "X" value or if it has an "X" value it will leave it
blank).
I want this to happen whether I click on the active cell or on a new cell
within the column.
Also, how do I do this if it requires a double click.
Thanks,
Brad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Toggle a cell

Hi
use the Selection_Change event of your worksheet. Put the following code in
your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub

Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
I've tried several methods but can't quite figure it out. How can I
write the code so that when I click on a cell within a column it will
toggle it (i.e. if blank, put an "X" value or if it has an "X" value
it will leave it blank).
I want this to happen whether I click on the active cell or on a new
cell within the column.
Also, how do I do this if it requires a double click.
Thanks,
Brad



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Toggle a cell

Thanks Frank,
This is not quite what I was looking for. I am specifically trying to
"toggle" the cell only when it is clicked on (or double-clicked), not just
when the cell becomes active. Further, even when the cell is active I would
like to be able to click on it again to toggle it again.
Thanks,
Brad

"Frank Kabel" wrote:

Hi
use the Selection_Change event of your worksheet. Put the following code in
your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub

Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
I've tried several methods but can't quite figure it out. How can I
write the code so that when I click on a cell within a column it will
toggle it (i.e. if blank, put an "X" value or if it has an "X" value
it will leave it blank).
I want this to happen whether I click on the active cell or on a new
cell within the column.
Also, how do I do this if it requires a double click.
Thanks,
Brad




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Toggle a cell

Hi
only processing the click event is not possible. What you could do is using
the Before_Doubleclick event instead of the selection_change event in the
same manner

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
Thanks Frank,
This is not quite what I was looking for. I am specifically trying to
"toggle" the cell only when it is clicked on (or double-clicked), not
just when the cell becomes active. Further, even when the cell is
active I would like to be able to click on it again to toggle it
again.
Thanks,
Brad

"Frank Kabel" wrote:

Hi
use the Selection_Change event of your worksheet. Put the following
code in your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub

Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
I've tried several methods but can't quite figure it out. How can I
write the code so that when I click on a cell within a column it
will toggle it (i.e. if blank, put an "X" value or if it has an
"X" value it will leave it blank).
I want this to happen whether I click on the active cell or on a new
cell within the column.
Also, how do I do this if it requires a double click.
Thanks,
Brad



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Toggle a cell

Thanks Frank. I got this work. One more question. After Doubleclick I do
not want the cell left open for editing. I have been able to turn off cell
editing at beginning of code but when I turn it on again at the end of the
code it appears to negate turning it off at the start. Here is what I have:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Application.EditDirectlyInCell = False
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub
Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
Application.EnableEvents = True
Application.EditDirectlyInCell = True
End Sub



"Frank Kabel" wrote:

Hi
only processing the click event is not possible. What you could do is using
the Before_Doubleclick event instead of the selection_change event in the
same manner

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
Thanks Frank,
This is not quite what I was looking for. I am specifically trying to
"toggle" the cell only when it is clicked on (or double-clicked), not
just when the cell becomes active. Further, even when the cell is
active I would like to be able to click on it again to toggle it
again.
Thanks,
Brad

"Frank Kabel" wrote:

Hi
use the Selection_Change event of your worksheet. Put the following
code in your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub

Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
I've tried several methods but can't quite figure it out. How can I
write the code so that when I click on a cell within a column it
will toggle it (i.e. if blank, put an "X" value or if it has an
"X" value it will leave it blank).
I want this to happen whether I click on the active cell or on a new
cell within the column.
Also, how do I do this if it requires a double click.
Thanks,
Brad






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Toggle a cell

Hi
try:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Application.EditDirectlyInCell = False
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub
Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
cancel=true
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
Thanks Frank. I got this work. One more question. After
Doubleclick I do not want the cell left open for editing. I have
been able to turn off cell editing at beginning of code but when I
turn it on again at the end of the code it appears to negate turning
it off at the start. Here is what I have: Private Sub
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.EditDirectlyInCell = False
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub
Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
Application.EnableEvents = True
Application.EditDirectlyInCell = True
End Sub



"Frank Kabel" wrote:

Hi
only processing the click event is not possible. What you could do
is using the Before_Doubleclick event instead of the
selection_change event in the same manner

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
Thanks Frank,
This is not quite what I was looking for. I am specifically trying
to "toggle" the cell only when it is clicked on (or
double-clicked), not just when the cell becomes active. Further,
even when the cell is active I would like to be able to click on it
again to toggle it again.
Thanks,
Brad

"Frank Kabel" wrote:

Hi
use the Selection_Change event of your worksheet. Put the following
code in your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub

Application.EnableEvents = False
If Target.Value < "" Then
Target.ClearContents
Else
Target.Value = "X"
End If
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

Brad K. wrote:
I've tried several methods but can't quite figure it out. How
can I write the code so that when I click on a cell within a
column it will toggle it (i.e. if blank, put an "X" value or if
it has an "X" value it will leave it blank).
I want this to happen whether I click on the active cell or on a
new cell within the column.
Also, how do I do this if it requires a double click.
Thanks,
Brad



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Toggle cell value Ken G. Excel Discussion (Misc queries) 9 April 9th 23 12:48 PM
Toggle Cell Colour Conditionally Ken McLennan[_2_] Excel Worksheet Functions 6 September 11th 08 04:55 PM
Need a button to click to toggle cell color on/off Tonso Excel Discussion (Misc queries) 1 February 7th 07 12:33 AM
Can I toggle the value of a cell by clicking directly on the cell? steve-o Excel Discussion (Misc queries) 3 July 17th 06 09:47 PM
Toggle True/False in a cell Dave Peterson[_3_] Excel Programming 2 October 10th 03 03:05 AM


All times are GMT +1. The time now is 11:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"