Solved

Excel - Event does not fire?

Posted on 1998-04-01
2
198 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 40 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Perhaps more familiar to developers who primarily use VBScript than to developers who tend to work only with Microsoft Office and Visual Basic for Applications (VBA), the Dictionary is a powerful and versatile class, and is useful …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now