Press space bar or click on mouse button to insert a check mark in a cell

Press space bar or click on mouse button to insert a check mark in a cell

Post by Dave » Sat, 25 Jul 2009 00:31:39

Hi,

I need a macro that would on pressing the space bar or click on mouse
button will insert a check mark in a cell.
I have MS Excel 2003.

thanks

Dave

 
 
 

Press space bar or click on mouse button to insert a check mark in a cell

Post by Rick Roths » Sat, 25 Jul 2009 01:04:32

How about in response to a double click (change the address for the cell in
the first If..Then statement to the actual address of your cell and use the
$ signs in the address)...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Target.Address = "$A$1" Then
Cancel = True
If Target.Value = "" Then
Target.Value = "X"
Else
Target.Value = ""
End If
End If
End Sub

To install this code, right click the tab at the bottom of the worksheet you
want this functionality on, select View Code from the popup menu that
appears and copy/paste the above code into the code window that appeared.
Now, go back to the worksheet and double click the cell to put the "X" in
the cell, then double click it again to clear it. Instead of the "X" I used,
you can change the font for the cell and then use any character you want.

--
Rick (MVP - Excel)

 
 
 

Press space bar or click on mouse button to insert a check mark in a cell

Post by Dave » Sat, 25 Jul 2009 05:00:06

On Jul 23, 11:04m, "Rick Rothstein"

> If Target.Value = "" T>en
> Target.Value>= "X"
> > Else
> Target>Value = "" >> End >f
> End>If> > End Sub
>
> To install this code, right click the tab at the bottom of the>worksheet you
> want this functionality on, select View Code from the p>pup menu that
> appears and copy/paste the above code into the code window >hat appeared.
> Now, go back to the worksheet and double click the cell to >ut the "X" in
> the cell, then double click it again to clear it. Instead of t>e "X" I used,
> you can change the font for the cell and then use any chara>te> you >ant.
>
> --
> Rick>(M>P - Excel<
>
> "Dave" wr>te>in message
>

> >> >>> > > Hi,
>
> > I need a macro that would n pressing the space bar or >l>ck on mouse
> > button will nsert a check m>r> in a cell.
> > I have >S >x>el 2003. >> >>>> thanks
>
> > Dave- Hide>qu>ted text -
>
> - Show quoted text -

Thanks for all your help. I am going to use Ricks code as below:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As
Boolean)
If Target.Address = "$A$1" Then
Cancel = True
If Target.Value = "" Then
Target.Value = "X"
Else
Target.Value = ""
End If
End If
End Sub


What If I had multiple cells where I would like this action to occur
could I do somethig as below:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As
Boolean)
If Target.Address = "$A$1" OR "$L$15" OR "$m$34" Then
Cancel = True
If Target.Value = "" Then
Target.Value = "X"
Else
Target.Value = ""
End If
End If
End Sub

thanks again
 
 
 

Press space bar or click on mouse button to insert a check mark in a cell

Post by Rick Roths » Sat, 25 Jul 2009 05:49:07

There are several ways to do it. The standard way is pretty much to
construct a Range referencing the cells in the range and test the
intersection of that range and the Target. To do this, replace this line in
my code...

If Target.Address = "$A$1" Then

with this one...

If Not Intersect(Target, Range("$A$1,$L$15,$M$34")) Is Nothing

--
Rick (MVP - Excel)




On Jul 23, 11:04 am, "Rick Rothstein"




Thanks for all your help. I am going to use Ricks code as below:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As
Boolean)
If Target.Address = "$A$1" Then
Cancel = True
If Target.Value = "" Then
Target.Value = "X"
Else
Target.Value = ""
End If
End If
End Sub


What If I had multiple cells where I would like this action to occur
could I do somethig as below:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As
Boolean)
If Target.Address = "$A$1" OR "$L$15" OR "$m$34" Then
Cancel = True
If Target.Value = "" Then
Target.Value = "X"
Else
Target.Value = ""
End If
End If
End Sub

thanks again