Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Enter Text in Cell on Click

I want to be able to do the following:
1. Click in a cell inside a named range ("DNS_zones_selection") and have "x"
entered into the clicked cell.
2. If the cell already has an entry, it should be erased.
3. You should be able to toggle the cell contents on and off by repeatedly
clicking on the same cell without clicking another cell.

The following code meets #1 and #2 above as long as you click in the target
cell, then click outside the target cell, then click back in the target
cell.

Is there a way to achieve all three goals without having to first click
outside the range?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If InRange(Target, Range("DNS_zones_selection")) Then
Select Case Target.Text
Case ""
Target.Value = "x"
Case Else
Target.Value = ""
End Select
End If
End Sub

Private Function InRange(rng1, rng2) As Boolean ' courtesy John Walkenbach,
"Excel 2000 Power Programming," Ch. 11, "in range.xls"
' Returns True if rng1 is a subset of rng2
InRange = False
If rng1.Parent.Parent.Name = rng2.Parent.Parent.Name Then
If rng1.Parent.Name = rng2.Parent.Name Then
If Union(rng1, rng2).Address = rng2.Address Then
InRange = True
End If
End If
End If
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Enter Text in Cell on Click

Have you thought about using the Worksheet_BeforeDoubleClick or
Worksheet_BeforeRightClick. You could use one to toggle on/off or you could use
both--one to put the X and one to clear the X.



Steven Drenker wrote:

I want to be able to do the following:
1. Click in a cell inside a named range ("DNS_zones_selection") and have "x"
entered into the clicked cell.
2. If the cell already has an entry, it should be erased.
3. You should be able to toggle the cell contents on and off by repeatedly
clicking on the same cell without clicking another cell.

The following code meets #1 and #2 above as long as you click in the target
cell, then click outside the target cell, then click back in the target
cell.

Is there a way to achieve all three goals without having to first click
outside the range?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If InRange(Target, Range("DNS_zones_selection")) Then
Select Case Target.Text
Case ""
Target.Value = "x"
Case Else
Target.Value = ""
End Select
End If
End Sub

Private Function InRange(rng1, rng2) As Boolean ' courtesy John Walkenbach,
"Excel 2000 Power Programming," Ch. 11, "in range.xls"
' Returns True if rng1 is a subset of rng2
InRange = False
If rng1.Parent.Parent.Name = rng2.Parent.Parent.Name Then
If rng1.Parent.Name = rng2.Parent.Name Then
If Union(rng1, rng2).Address = rng2.Address Then
InRange = True
End If
End If
End If
End Function


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Enter Text in Cell on Click

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng as Range
set rng = Intersect(Target,Range("DNS_zones_selection"))
If Not rng is Nothing Then

Select Case rng(1).Text
Case ""
rng(1).Value = "x"
Case Else
rng(1).Value = ""
End Select
Application.EnableEvents = False
rng(1).offset(0,1).Select
Application.EnableEvents = True
End If
End Sub

--
Regards,
Tom Ogilvy

--
Regards,
Tom Ogilvy


"Steven Drenker" wrote in message
news:BFFE7798.13D0EF%sdrenkerNOSPAM@SPAMNOpacbell. net...
I want to be able to do the following:
1. Click in a cell inside a named range ("DNS_zones_selection") and have

"x"
entered into the clicked cell.
2. If the cell already has an entry, it should be erased.
3. You should be able to toggle the cell contents on and off by repeatedly
clicking on the same cell without clicking another cell.

The following code meets #1 and #2 above as long as you click in the

target
cell, then click outside the target cell, then click back in the target
cell.

Is there a way to achieve all three goals without having to first click
outside the range?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If InRange(Target, Range("DNS_zones_selection")) Then
Select Case Target.Text
Case ""
Target.Value = "x"
Case Else
Target.Value = ""
End Select
End If
End Sub

Private Function InRange(rng1, rng2) As Boolean ' courtesy John

Walkenbach,
"Excel 2000 Power Programming," Ch. 11, "in range.xls"
' Returns True if rng1 is a subset of rng2
InRange = False
If rng1.Parent.Parent.Name = rng2.Parent.Parent.Name Then
If rng1.Parent.Name = rng2.Parent.Name Then
If Union(rng1, rng2).Address = rng2.Address Then
InRange = True
End If
End If
End If
End Function



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
I type data into a cell that changes when I click enter - why? cruiser Excel Discussion (Misc queries) 2 March 30th 07 12:49 AM
Click "Enter" move to cell to the right, not down in Excel Art Bahrnone Excel Worksheet Functions 1 March 20th 07 03:38 AM
How to make the current date appear when i click 'enter' in a cell Matt_07 Excel Worksheet Functions 1 January 30th 07 09:32 AM
enter data in cell but cannot save until click off cell in excel T70McCains Excel Discussion (Misc queries) 1 November 18th 05 05:06 PM
WHY DO I HAVE TO CLICK ON THE CELL & ENTER FOR THE VLOOKUP TOWORK Half Manx Excel Discussion (Misc queries) 4 September 29th 05 12:12 PM


All times are GMT +1. The time now is 01:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"