Solved

Excel - Event does not fire?

Posted on 1998-04-01
2
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

740 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