Counting clicks

R

rengewwj

I want to count the clicks in any of a large range of cells in one column.
This is for purposes of collecting clicks like a person making hash marks on
an inventory count sheet. There is some brilliant code on another forum but
it only works on a couple or a few cells, as named within the code. I cannot
make it work throughout a column. This is the code:

Option Explicit
Dim oldvalue As Double
Private Sub Worksheet_SelectionChange(ByVal target As Range)
If target.Address = "$A$5" Or target.Address = "$B$5" Then

oldvalue = target

Application.EnableEvents = False
If target.Value = 0 Then oldvalue = 0
target.Value = 1 + oldvalue
oldvalue = target.Value
Application.EnableEvents = True
End If
End Sub
Sub fixit()
Application.EnableEvents = True
End Sub
 
M

Mike H

Hi,

Try this. the fixit subroutine has probably been added for debugging and
does nothing


Option Explicit
Dim oldvalue As Double
Private Sub Worksheet_SelectionChange(ByVal target As Range)
If target.Column = (1) And target.Cells.Count = 1 Then

oldvalue = target

Application.EnableEvents = False
If target.Value = 0 Then oldvalue = 0
target.Value = 1 + oldvalue
oldvalue = target.Value
Application.EnableEvents = True
End If
End Sub

Mike
 
O

Otto Moehrbach

Change your "IF" statement to something like:
If Not Intersect(Target, Columns("B:B")) Is Nothing Then
Change the column to suit. HTH Otto
 
G

Gary''s Student

Perhaps:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Then
Application.EnableEvents = False
Target.Value = Target.Value + 1
Application.EnableEvents = True
End If
End Sub
 
R

rengewwj

Works like a charm. Thank you.

Mike H said:
Hi,

Try this. the fixit subroutine has probably been added for debugging and
does nothing


Option Explicit
Dim oldvalue As Double
Private Sub Worksheet_SelectionChange(ByVal target As Range)
If target.Column = (1) And target.Cells.Count = 1 Then

oldvalue = target

Application.EnableEvents = False
If target.Value = 0 Then oldvalue = 0
target.Value = 1 + oldvalue
oldvalue = target.Value
Application.EnableEvents = True
End If
End Sub

Mike
 
B

Bernard Liengme

Small typo here. For first statement use
If Not Intersect(Target, Range("A:A")) is Nothing Then

best wishes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top