Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Lock worksheet, based on dropdown selection prior worksheet | New Users to Excel | |||
count based on selection from drop down list | Excel Worksheet Functions | |||
No cell-selection in worksheet | Excel Programming | |||
Worksheet Selection | Excel Programming | |||
Selection.count isnt working | Excel Programming |