Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Order of selecting unprotected cells | Excel Discussion (Misc queries) | |||
Counting empty cells within a range of cells | New Users to Excel | |||
Counting empty cells within a range of cells | New Users to Excel | |||
Heps to design Locked/Unlocked cells in protected worksheet | Excel Discussion (Misc queries) | |||
Convert data of cells to any type: Number, Date&Time, Text | Excel Discussion (Misc queries) |