Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default On Click Event?, and how to use

Is there a way for me to write a macro to have certain
cells toggle between X and "" every time they are
clicked? Does this need to be done on the "Module" level
if it is possible? I have never been able to find how I
write macros there. Help appreciated! :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default On Click Event?, and how to use

In the module for the worksheet in question, use th
Worksheet_SelectionChange event. Here is an example of how that can b
accomplished…

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 3 And Target.Column = 3 Then
If Target.Value < "" Then
Target.Value = ""
Else
Target.Value = "X"
End If
End If
End Sub

Piku

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default On Click Event?, and how to use

How about just changing if you select the cell. No clicking necessary.
Right click sheet tabview codeinsert this. As written works on only column
A.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
If UCase(Target) = "X" Then
Target = ""
Else
Target = "X"
End If
End Sub


--
Don Guillett
SalesAid Software

"Wandering Mage" wrote in message
...
Is there a way for me to write a macro to have certain
cells toggle between X and "" every time they are
clicked? Does this need to be done on the "Module" level
if it is possible? I have never been able to find how I
write macros there. Help appreciated! :)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default On Click Event?, and how to use

Thanks guys, to both of you. Now further on the same
problem. First, the macro will error if you accidentally
select more than one cell. My project entails dummy
proofing the thing. Is there away to allow you to only
select one cell, or is there a way to make it swich the
multiple cells all at once (that would be really cool).
Second, I guess I would also prefer that it not actually
select the cell but just change it. Even some way to
insert something like:
returnto = ActiveWindow.RangeSelection.Address
Range(returnto).Select
would be good, but this particualar event calls out after
the cell(s) is/are already selected. Thanks again. Hope
you can help.
-----Original Message-----
In the module for the worksheet in question, use the
Worksheet_SelectionChange event. Here is an example of

how that can be
accomplished.

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Target.Row = 3 And Target.Column = 3 Then
If Target.Value < "" Then
Target.Value = ""
Else
Target.Value = "X"
End If
End If
End Sub

Pikus


---
Message posted from http://www.ExcelForum.com/

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default On Click Event?, and how to use

1, insert this line as the FIRST line in the macro
on error resume next
2. The only way to change a cell without selecting is to pre-define it
range("a3").value="X"



--
Don Guillett
SalesAid Software

"thanks and more" wrote in message
...
Thanks guys, to both of you. Now further on the same
problem. First, the macro will error if you accidentally
select more than one cell. My project entails dummy
proofing the thing. Is there away to allow you to only
select one cell, or is there a way to make it swich the
multiple cells all at once (that would be really cool).
Second, I guess I would also prefer that it not actually
select the cell but just change it. Even some way to
insert something like:
returnto = ActiveWindow.RangeSelection.Address
Range(returnto).Select
would be good, but this particualar event calls out after
the cell(s) is/are already selected. Thanks again. Hope
you can help.
-----Original Message-----
In the module for the worksheet in question, use the
Worksheet_SelectionChange event. Here is an example of

how that can be
accomplished.

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Target.Row = 3 And Target.Column = 3 Then
If Target.Value < "" Then
Target.Value = ""
Else
Target.Value = "X"
End If
End If
End Sub

Pikus


---
Message posted from
http://www.ExcelForum.com/

.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default On Click Event?, and how to use

For multiple cells you can do something like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range
For Each cel In Target
If cel.Value < "" Then
cel.Value = ""
Else
cel.Value = "X"
End If
Next cel
End Sub

If you only want certain cells to be affected you can put in another i
statement:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cel As Range
For Each cel In Target
If cel.Column < 3 Then
If cel.Value < "" Then
cel.Value = ""
Else
cel.Value = "X"
End If
End If
Next cel
End Sub

How's that? - Piku

--
Message posted from http://www.ExcelForum.com

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
Before Double Click Event gregork Excel Programming 4 February 9th 04 09:17 AM
Before Right Click event mohsinb[_8_] Excel Programming 10 December 22nd 03 08:47 AM
Click Event Nichevo Excel Programming 2 December 4th 03 04:31 AM
CommandBarButton click event Javi Excel Programming 0 November 3rd 03 03:05 PM
Click event on Scrollbar Sam K Excel Programming 1 July 21st 03 07:58 AM


All times are GMT +1. The time now is 02:28 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"