ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SelectionChange Event question (https://www.excelbanter.com/excel-programming/439369-selectionchange-event-question.html)

Ted M H

SelectionChange Event question
 
I want a simple message box that displays whenever I create a new selection
in a worksheet. The message box needs to display both the address of the
last selection and the address of the new selection. I have the following
solution:

Dim LastSelected As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox LastSelected & Target.Address
LastSelected = Target.Address
End Sub

This works fine except for the first time through, when LastSelected is
empty. How can I get the initial selection to display in the message box?

Many thanks.


Don Guillett[_2_]

SelectionChange Event question
 

You could store it in a cell somewhere.
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Ted M H" wrote in message
...
I want a simple message box that displays whenever I create a new selection
in a worksheet. The message box needs to display both the address of the
last selection and the address of the new selection. I have the following
solution:

Dim LastSelected As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox LastSelected & Target.Address
LastSelected = Target.Address
End Sub

This works fine except for the first time through, when LastSelected is
empty. How can I get the initial selection to display in the message box?

Many thanks.




All times are GMT +1. The time now is 04:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com