Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default add 1 when click

Hi,
does anyone know how to program a cell when every single
click on that cell with mouse button, the value of the
cell will add 1. for example: Cell A1 had a value of 7,
when i click on cell A1, the value will go up to 8 and so
on.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default add 1 when click

Dylan,

Right-click the Sheet Tab, View Code, Insert this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 Then Target.Value = Target.Value + 1
End Sub

If the Column is A then add 1


It will activate every time you select the cell. Unlike clicking a cell it
only triggers when you change the selection from a different cell.


"Dylan" wrote in message
...
Hi,
does anyone know how to program a cell when every single
click on that cell with mouse button, the value of the
cell will add 1. for example: Cell A1 had a value of 7,
when i click on cell A1, the value will go up to 8 and so
on.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default add 1 when click

Dylan,

Right-click the Sheet Tab, View Code, Insert this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 Then Target.Value = Target.Value + 1
End Sub

If the Column is A then it adds 1

It will activate every time you select the cell. Unlike clicking a cell it
only triggers when you change the selection from a different cell.

Rob


"Dylan" wrote in message
...
Hi,
does anyone know how to program a cell when every single
click on that cell with mouse button, the value of the
cell will add 1. for example: Cell A1 had a value of 7,
when i click on cell A1, the value will go up to 8 and so
on.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default add 1 when click


-----Original Message-----
Dylan,

Right-click the Sheet Tab, View Code, Insert this:

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Target.Column = 1 Then Target.Value = Target.Value

+ 1
End Sub

If the Column is A then it adds 1

It will activate every time you select the cell. Unlike

clicking a cell it
only triggers when you change the selection from a

different cell.

Rob


"Dylan" wrote in message
...
Hi,
does anyone know how to program a cell when every single
click on that cell with mouse button, the value of the
cell will add 1. for example: Cell A1 had a value of 7,
when i click on cell A1, the value will go up to 8 and

so
on.



.


hi Rob,

thanks for help. it works. what i see is that the whole
column will be affected. could you teach me how to amend
the script for only a particular Cell instead? also could
i do it such that the value change On_click instead of
clicking elsewhere then back on the cell. thanks very much.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default add 1 when click

Hi Dylan
One way: Change the code to the following (now only A1 is counted):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then
Exit Sub
Else
Target.Value = Target.Value + 1
end if
End Sub

hi Rob,

thanks for help. it works. what i see is that the whole
column will be affected. could you teach me how to amend
the script for only a particular Cell instead? also could
i do it such that the value change On_click instead of
clicking elsewhere then back on the cell. thanks very much.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default add 1 when click

Hi Dylan,

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If not intersect (Target, Range("A1")) Is Nothing Then
Target.Value = Target.Value + 1
End If
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Dylan" wrote in message
...

-----Original Message-----
Dylan,

Right-click the Sheet Tab, View Code, Insert this:

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Target.Column = 1 Then Target.Value = Target.Value

+ 1
End Sub

If the Column is A then it adds 1

It will activate every time you select the cell. Unlike

clicking a cell it
only triggers when you change the selection from a

different cell.

Rob


"Dylan" wrote in message
...
Hi,
does anyone know how to program a cell when every single
click on that cell with mouse button, the value of the
cell will add 1. for example: Cell A1 had a value of 7,
when i click on cell A1, the value will go up to 8 and

so
on.



.


hi Rob,

thanks for help. it works. what i see is that the whole
column will be affected. could you teach me how to amend
the script for only a particular Cell instead? also could
i do it such that the value change On_click instead of
clicking elsewhere then back on the cell. thanks very much.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default add 1 when click

Dylan,

I don't think there is a trivial way to capture onclick for a worksheet.
Because SelectionChange fires even when you use the cursor keys to enter
that cell, I suggest another approach:

Create a button and assign this macro to it, which in this example
increments selection if it falls within the range A1:B20
If selection is outside of bounds, then it beeps as an error.

Sub Increment_Click()
Dim rng As Range, rngSel As Range

Set rngSel = Intersect(Selection, Range("A1:B20"))
If Not rngSel Is Nothing Then
For Each rng In rngSel
rng.Value = rng.Value + 1
Next
Else
Beep
End If
End Sub


Rob


"Dylan" wrote in message
...

-----Original Message-----
Dylan,

Right-click the Sheet Tab, View Code, Insert this:

Private Sub Worksheet_SelectionChange(ByVal Target As

Range)
If Target.Column = 1 Then Target.Value = Target.Value

+ 1
End Sub

If the Column is A then it adds 1

It will activate every time you select the cell. Unlike

clicking a cell it
only triggers when you change the selection from a

different cell.

Rob


"Dylan" wrote in message
...
Hi,
does anyone know how to program a cell when every single
click on that cell with mouse button, the value of the
cell will add 1. for example: Cell A1 had a value of 7,
when i click on cell A1, the value will go up to 8 and

so
on.



.


hi Rob,

thanks for help. it works. what i see is that the whole
column will be affected. could you teach me how to amend
the script for only a particular Cell instead? also could
i do it such that the value change On_click instead of
clicking elsewhere then back on the cell. thanks very much.



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
How do I create a click on + symbol to open a root and click on -. changeyourbodychallenge.com Excel Discussion (Misc queries) 1 December 28th 09 03:22 PM
How to change syperlink from single click to double click syperlinker Excel Worksheet Functions 0 June 13th 08 05:01 PM
Disabling click and right-click on the Picture I inserted in an Excel document [email protected] Excel Worksheet Functions 1 June 2nd 06 09:13 PM
Click on graph bar to execute a double-click in a pivot table cell [email protected] Charts and Charting in Excel 4 August 3rd 05 01:37 AM
Click on cell-calendar drops down-click on date-date fills cell. . George Setting up and Configuration of Excel 1 April 15th 05 08:22 AM


All times are GMT +1. The time now is 07:23 AM.

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"