ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell Select (https://www.excelbanter.com/excel-programming/335451-cell-select.html)

Tom Melosi[_3_]

Cell Select
 
Is there a way to determine if a cell is selected? I tried to use the
onchange event, but that only works when something is changed. If a certain
cell is selected, I would like to test and make sure another cell has data
in it.

For example, the user must choose a value from a data validation drop down
list in cell C7 before the cascading list in cell D8 is populated. If they
try to select cell D8 first, I want to display a message and then set cell
C7 as the active cell.

I'm not sure if there is a way to capture a cell select versus a change???

Thanks,

Tom



Tom Ogilvy

Cell Select
 
Use the selectionchange event in xl97 and later

See Chip Pearson's page on events
http://www.cpearson.com/excel/events.htm

Also, if you change the selection within the SelectionChange event, you
should disable events (reenable them at the end) within the event to prevent
recursive calls.

--
Regards,
Tom Ogilvy

"Tom Melosi" wrote in message
...
Is there a way to determine if a cell is selected? I tried to use the
onchange event, but that only works when something is changed. If a

certain
cell is selected, I would like to test and make sure another cell has data
in it.

For example, the user must choose a value from a data validation drop down
list in cell C7 before the cascading list in cell D8 is populated. If

they
try to select cell D8 first, I want to display a message and then set cell
C7 as the active cell.

I'm not sure if there is a way to capture a cell select versus a change???

Thanks,

Tom





Bob Phillips[_6_]

Cell Select
 
Try the worksheet select event

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$D$8" Then
With Target
'do your stuff
End With
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Tom Melosi" wrote in message
...
Is there a way to determine if a cell is selected? I tried to use the
onchange event, but that only works when something is changed. If a

certain
cell is selected, I would like to test and make sure another cell has data
in it.

For example, the user must choose a value from a data validation drop down
list in cell C7 before the cascading list in cell D8 is populated. If

they
try to select cell D8 first, I want to display a message and then set cell
C7 as the active cell.

I'm not sure if there is a way to capture a cell select versus a change???

Thanks,

Tom





Tom Melosi[_3_]

Cell Select
 
Thanks, worked great!

"Bob Phillips" wrote in message
...
Try the worksheet select event

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$D$8" Then
With Target
'do your stuff
End With
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)




Tom Melosi[_3_]

Cell Select
 
The selectionchange event is what I was looking for - Thanks!

"Tom Ogilvy" wrote in message
...
Use the selectionchange event in xl97 and later

See Chip Pearson's page on events
http://www.cpearson.com/excel/events.htm

Also, if you change the selection within the SelectionChange event, you
should disable events (reenable them at the end) within the event to

prevent
recursive calls.

--
Regards,
Tom Ogilvy




TommySzalapski[_5_]

Cell Select
 

Use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Target will be the range of the selected cell
If target.row = [row number] and target.column = [column number
then
[your code]
End If
End Sub

or something like tha

--
TommySzalapsk
-----------------------------------------------------------------------
TommySzalapski's Profile: http://www.excelforum.com/member.php...fo&userid=2556
View this thread: http://www.excelforum.com/showthread.php?threadid=38994



All times are GMT +1. The time now is 02:12 PM.

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