Solved

Excel - Event does not fire?

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

27 Experts available now in Live!

Get 1:1 Help Now