Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Activate code by clicking in cell

What is the best way to code so that when clicking on one of a few dozen
cells that cell is toggled between blank and an check mark symbol?
I found a post that explains using TargetAddress in the sheet code but I
would need a separate routine for each cell that I want to react this way.
Seems like there might be a better way.
I want to put the check box in the cell rather than using the check box
control becuase I have set up extensive conditional formatting of the cells
based on whether there is a check mark or not.

Thanks in advance for any help.
ed
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Activate code by clicking in cell

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrHandler
If Target.Count 1 Then Exit Sub
If Not Intersect(Target, Range("F14:H26")) Is Nothing Then
Application.EnableEvents = False
If Len(Trim(Target)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End if
ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"expect_ed" wrote:

What is the best way to code so that when clicking on one of a few dozen
cells that cell is toggled between blank and an check mark symbol?
I found a post that explains using TargetAddress in the sheet code but I
would need a separate routine for each cell that I want to react this way.
Seems like there might be a better way.
I want to put the check box in the cell rather than using the check box
control becuase I have set up extensive conditional formatting of the cells
based on whether there is a check mark or not.

Thanks in advance for any help.
ed

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Activate code by clicking in cell

This worksheet code will work on an abritrary collection of cells, but with
double-click:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Set r = Union(Range("A1"), Range("B2"), Range("C3"))
If Intersect(r, Target) Is Nothing Then
Cancel = False
Exit Sub
End If
If IsEmpty(Target) Then
Target.Value = "a"
Cancel = True
Else
Target.Value = ""
Cancel = True
End If
End Sub

and format the cells in question as font-webdings

--
Gary''s Student - gsnu200735


"expect_ed" wrote:

What is the best way to code so that when clicking on one of a few dozen
cells that cell is toggled between blank and an check mark symbol?
I found a post that explains using TargetAddress in the sheet code but I
would need a separate routine for each cell that I want to react this way.
Seems like there might be a better way.
I want to put the check box in the cell rather than using the check box
control becuase I have set up extensive conditional formatting of the cells
based on whether there is a check mark or not.

Thanks in advance for any help.
ed

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Activate code by clicking in cell

This worked well, for a while.
First I copied your code directly. Works fine.
Then I tried using a named range, since I wanted to limit the feature to
non-adjacent cells. That also worked fine.
Then I wanted to use a check instead of an X, so I changed the line
Target.Value = "X" to
Target.Value = Cells (1,15) and put a checkbox in O1. This also worked fine.

So now I'm ready to try it in my project.
I tried creating a named range with all the needed cells, but there were too
many, so I played around a bit with adding named ranges into one named range,
but got stuck, so I decided to try your code with my modifications on the
named range that is a subset of my total desired range.
This would not work.
To trouble shoot I tried several ideas.
1. The Worksheet code already had commandbutton code. I hought that might
somehow interfere, so I commented that out. No difference.
2. The cells I am using had validation turned on so I could have a dropdown
for the checkbox. I turned that off. Still would not work.
3. Tried using a more limited direct reference range instead of the named
range. No good. Also tried inserting Gary's Stuident code with the Union
(range, range,etc.) somewhere along here.
4. Went back to a direct value of "X" for the Target.Value. Nope
5. Went back to the practice sheet. Not sure what changes I made, if any,
but now that code will not work.
6. In the practice sheet, started over with a fresh paste of your code. no
7. Tried in a fresh tab. Still nothing.
8. Tried a fresh workbook. Cut and paste the code. Still will not work.
Now I'm stumped.
HELP (plese)


"Tom Ogilvy" wrote:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrHandler
If Target.Count 1 Then Exit Sub
If Not Intersect(Target, Range("F14:H26")) Is Nothing Then
Application.EnableEvents = False
If Len(Trim(Target)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End if
ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"expect_ed" wrote:

What is the best way to code so that when clicking on one of a few dozen
cells that cell is toggled between blank and an check mark symbol?
I found a post that explains using TargetAddress in the sheet code but I
would need a separate routine for each cell that I want to react this way.
Seems like there might be a better way.
I want to put the check box in the cell rather than using the check box
control becuase I have set up extensive conditional formatting of the cells
based on whether there is a check mark or not.

Thanks in advance for any help.
ed

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
Run Code On Activate Theresa Excel Worksheet Functions 5 December 18th 07 05:47 AM
How can I use VB code to execute macro when double-clicking cell? JDay01 Excel Programming 2 June 13th 06 03:12 PM
Running code by clicking on a hyperlink cell matpj[_53_] Excel Programming 3 March 29th 06 02:27 PM
Code for making a cell chage color by dbl clicking, with either a Zan Dorris Excel Programming 1 February 13th 06 04:00 PM
Activate code in cell Steve Excel Programming 5 August 18th 05 07:44 PM


All times are GMT +1. The time now is 04:07 PM.

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"