placing an "X" in a cell

R

rwfster

Is there any way to place an "X" in any cell of my choosiing by clicking on
it or by touching the cell with a stylus from a touch screen tablet?
 
G

Gary''s Student

How about a double-click??

Insert the following event macro in the worksheet code area:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
Target.Value = "X"
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
 
A

Alojz

Gary, it works well, yet I consider it a bit dangerous as u cannot make undo
when accidentally double click...
 
G

Greg Wilson

If the cell range is constant then I'd go with checkboxes from the Forms
toolbar and forget the "X". If the number of cells are many and/or change
then this can become a maintenance nightmare. If so, then this has only one
rectangle to manage:

1. Put a rectangle on the worksheet
2. Adjust its size and position so that it just covers the desired cell range
3. Make it invisible by formatting its fill and line properties to No Fill
and No Line respectively
4. Paste the following code to a standard code module
5. Assign the TogX macro to the rectangle

Private Declare Function GetCursorPos Lib "user32.dll" ( _
ByRef lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type

Sub TogX()
Dim c As Range
Dim cp As POINTAPI
GetCursorPos cp
With ActiveSheet
.Unprotect 'optional
With .Shapes(Application.Caller)
.Visible = False
Set c = ActiveWindow.RangeFromPoint(cp.x, cp.y)
.Visible = True
End With
If c.Value = "X" Then c.Value = "" Else c.Value = "X"
.Protect 'optional
End With
Set c = Nothing
End Sub

Regards
Greg
 
A

amontes

Is there any way to place an "X" in any cell of my choosiing by clicking on
it or by touching the cell with a stylus from a touch screen tablet?

Try this for toggling:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)

Application.EnableEvents = False
If StrComp(Target.Text, "X", vbTextCompare) = 0 Then
Target.Value = ""
Else
Target.Value = "X"
End If
Application.EnableEvents = True
End Sub
 
Top