?
Solved

Excel - Event does not fire?

Posted on 1998-04-01
2
Medium Priority
?
208 Views
Last Modified: 2008-02-01

The following code is supposed to execute whenever a selection change occurs (I assume that is when you move from one cell to another), however, it does not seem to work this way on my computer. (Excel 97)

Option Explicit

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
         MsgBox("Selection change event")
    End Sub

Can anyone explain why this is so?
0
Comment
Question by:idek1
2 Comments
 
LVL 3

Accepted Solution

by:
frazer earned 160 total points
ID: 1612066
Hi,

The code is correct and works on my computer (excel 97).
Have you put the code into the worksheet or is it in a module?
If it is not in the worksheet you can do so by going to the VBA editor, selecting the required sheet, then change the word (general) at the top of the module to worksheet, this in turn will change (declarations) to SelectionChange.
That will produce the private sub for you then you just need to enter your code.  e.g.
MsgBox("Selection change event")

Hope this helps

Frazer

0
 

Author Comment

by:idek1
ID: 1612067
Thank you frazer,
Yes, my code was in a module, and putting it into the worksheet solved the problem.
However, i do not understand why the code needs to be in the worksheet rather than the module: everything else (VBA code including other events like button clicks etc.) is in a module.

Also is the SelectionChange event something that is new to Excel97? If so, is there a way to get similar behaviour in previous versions of Excel?
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question