Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
aftamath
 
Posts: n/a
Default Click events on Ecel Cells

i would like to click on a cell in a worksheet and have the string value "X"
either inserted or removed from that cell upon clicking. Is this possible?
  #2   Report Post  
David McRitchie
 
Posts: n/a
Default

A selection change would be the closest match for that, I would suggest
using a double-click event.

More information in
http://www.mvps.org/dmcritchie/excel/event.htm

To install right click on the sheet tab, View Code, plop the following code in.
This is setup to toggle value in Column 1 on a double-click, but you can modify code.

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal _
Target As Range, Cancel As Boolean)
Cancel = True 'Get out of edit mode
If Target.Column = 1 Then
If Trim(Target.Value) = "" Then
Target.Value = "X"
ElseIf UCase(Target.Value) = "X" Then
Target.Value = ""
Else
MsgBox "Cannot toggle switch in " & Target.Address(0, 0)
End If
End If
End Sub

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"aftamath" wrote in message ...
i would like to click on a cell in a worksheet and have the string value "X"
either inserted or removed from that cell upon clicking. Is this possible?



  #3   Report Post  
aftamath
 
Posts: n/a
Default

That worked great, it was what I was looking for, but what's the syntax if I
want the same thing for a range of cells, say $B$6:$D$12, instead of one
column?

"David McRitchie" wrote:

A selection change would be the closest match for that, I would suggest
using a double-click event.

More information in
http://www.mvps.org/dmcritchie/excel/event.htm

To install right click on the sheet tab, View Code, plop the following code in.
This is setup to toggle value in Column 1 on a double-click, but you can modify code.

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal _
Target As Range, Cancel As Boolean)
Cancel = True 'Get out of edit mode
If Target.Column = 1 Then
If Trim(Target.Value) = "" Then
Target.Value = "X"
ElseIf UCase(Target.Value) = "X" Then
Target.Value = ""
Else
MsgBox "Cannot toggle switch in " & Target.Address(0, 0)
End If
End If
End Sub

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"aftamath" wrote in message ...
i would like to click on a cell in a worksheet and have the string value "X"
either inserted or removed from that cell upon clicking. Is this possible?




  #4   Report Post  
David McRitchie
 
Posts: n/a
Default

You could eliminate the test for Column 1 to be non restrictive, or to specifically
make sure you are in the range $B$6:$D$12 or any other range ie. $B:$D

If Intersect(Range("$B$6:$D$12"), Range(target(1).Address) Then
'....coding
End If

More information on INTERSECT in
http://www.mvps.org/dmcritchie/excel/proper.htm
http://www.mvps.org/dmcritchie/excel/event.htm
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"aftamath" wrote ...
That worked great, it was what I was looking for, but what's the syntax if I
want the same thing for a range of cells, say $B$6:$D$12, instead of one
column?



  #5   Report Post  
Gord Dibben
 
Posts: n/a
Default

afta

Change David's code to.........

Private Sub Worksheet_BeforeDoubleClick(ByVal _
Target As Range, Cancel As Boolean)
Cancel = True 'Get out of edit mode
If Not Application.Intersect(Range("$B$6:$D$12") _
, Target) Is Nothing Then
If Trim(Target.Value) = "" Then
Target.Value = "X"
ElseIf UCase(Target.Value) = "X" Then
Target.Value = ""
Else
MsgBox "Cannot toggle switch in " & Target.Address(0, 0)
End If
End If
End Sub


Gord Dibben Excel MVP

On Wed, 28 Sep 2005 07:09:11 -0700, "aftamath"
wrote:

That worked great, it was what I was looking for, but what's the syntax if I
want the same thing for a range of cells, say $B$6:$D$12, instead of one
column?

"David McRitchie" wrote:

A selection change would be the closest match for that, I would suggest
using a double-click event.

More information in
http://www.mvps.org/dmcritchie/excel/event.htm

To install right click on the sheet tab, View Code, plop the following code in.
This is setup to toggle value in Column 1 on a double-click, but you can modify code.

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal _
Target As Range, Cancel As Boolean)
Cancel = True 'Get out of edit mode
If Target.Column = 1 Then
If Trim(Target.Value) = "" Then
Target.Value = "X"
ElseIf UCase(Target.Value) = "X" Then
Target.Value = ""
Else
MsgBox "Cannot toggle switch in " & Target.Address(0, 0)
End If
End If
End Sub

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"aftamath" wrote in message ...
i would like to click on a cell in a worksheet and have the string value "X"
either inserted or removed from that cell upon clicking. Is this possible?





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
Order of selecting unprotected cells sp2 tester Excel Discussion (Misc queries) 2 August 15th 05 04:07 PM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 2 May 2nd 05 08:53 AM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 0 April 7th 05 12:47 AM
Heps to design Locked/Unlocked cells in protected worksheet Kevin Excel Discussion (Misc queries) 0 December 30th 04 07:09 AM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM


All times are GMT +1. The time now is 02:26 AM.

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"