ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   worksheet selection count (https://www.excelbanter.com/excel-programming/377743-worksheet-selection-count.html)

Kelzina

worksheet selection count
 
hi,
i need to write a subroutine that will count the number of times a worksheet
is selected. so everytime the worksheet is selected i need to add one to the
value in Cell A1... the only line of code i was given is...

range("A1")=range("A1")+1
can anyone help???
thanx

--
"The difference between Possible and Impossible is the measure of ones will"

Bob Phillips

worksheet selection count
 
Private Sub Worksheet_Activate()
With Activesheet.Range("A1")
.Value = .Value + 1
End With
End Sub

This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Kelzina" wrote in message
...
hi,
i need to write a subroutine that will count the number of times a

worksheet
is selected. so everytime the worksheet is selected i need to add one to

the
value in Cell A1... the only line of code i was given is...

range("A1")=range("A1")+1
can anyone help???
thanx

--
"The difference between Possible and Impossible is the measure of ones

will"



big t

worksheet selection count
 
Hi Kelzina,

Your code is correct - you just need to put it in the Worksheet_Activate bit
for the worksheet you are interested in.

Go to the VB Environment (Alt + F11) and double click your worksheet in the
Project Explorer. Select "Worksheet" in the left hand drop down box. Select
"Activate" in the right hand drop down box. Enter your code in the Sub it
creates.

You should end up with something like this:

Private Sub Worksheet_Activate()
Range("A1") = Range("A1") + 1
End Sub

hth
big t


"Kelzina" wrote:

hi,
i need to write a subroutine that will count the number of times a worksheet
is selected. so everytime the worksheet is selected i need to add one to the
value in Cell A1... the only line of code i was given is...

range("A1")=range("A1")+1
can anyone help???
thanx

--
"The difference between Possible and Impossible is the measure of ones will"


Gary''s Student

worksheet selection count
 
In worksheet code:

Private Sub Worksheet_Activate()
Range("A1").Value = Range("A1").Value + 1
End Sub

REMEMBER: worksheet code
--
Gary's Student


"Kelzina" wrote:

hi,
i need to write a subroutine that will count the number of times a worksheet
is selected. so everytime the worksheet is selected i need to add one to the
value in Cell A1... the only line of code i was given is...

range("A1")=range("A1")+1
can anyone help???
thanx

--
"The difference between Possible and Impossible is the measure of ones will"



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com