Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Run Code on Cell Select

Hello,

I have a couple of questions on Excel Spreadsheet. I have a protected
worksheet that does not allow users to select locked or unlocked cells.
Ideally, I would like users to have a cell that when clicked on, runs a bit
of code. I thought I could accomplish by inserting a button, then setting
background to opaque and shawdows to false. This does work, but you can
still see outline off the button (which I do not want). Any other way to
accomplish this?

I am willing to compromise and let the protection of the form allow users to
select locked cells if necessary. But would also like to have the mouse
change to a different pointer when over that cell (which was working with the
button as well).

Thanks for any ideas!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run Code on Cell Select

You can use the SelectionChange event procedure of the workbook to detect
when a focus moves to a cell.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If StrComp(Target.Address, "$A$1", vbBinaryCompare) = 0 Then
' user selected A1
' your code here
End If
End Sub

However, if you are not allowing the user to select any cells, locked or
unlocked, this won't work since focus can never be set to a cell. In this
case, have only two options that I can think of. The first is to create a
menu item or commandbar that the user can click to run some code. The other
option is to drop a Forms or OLE button directly on to the worksheet and
attach some code to the button.

Finally, you cannot change the cursor when the user hovers over a cell. You
can change it with VBA code but such code won't be triggered if the cursor
just hovers over, without actually selecting, a cell.

My preference is to always allow the user to select any cells he wants, even
those that are locked. The reason is that the user may use the selection
indicator and row/column heading colors to highlight cells to make things
easier to read, especially in a large data table.

I guess the bottom line is that you can't really do any of the things you
want to.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

"Luke Bailey" wrote in message
...
Hello,

I have a couple of questions on Excel Spreadsheet. I have a protected
worksheet that does not allow users to select locked or unlocked cells.
Ideally, I would like users to have a cell that when clicked on, runs a
bit
of code. I thought I could accomplish by inserting a button, then setting
background to opaque and shawdows to false. This does work, but you can
still see outline off the button (which I do not want). Any other way to
accomplish this?

I am willing to compromise and let the protection of the form allow users
to
select locked cells if necessary. But would also like to have the mouse
change to a different pointer when over that cell (which was working with
the
button as well).

Thanks for any ideas!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Run Code on Cell Select

Interesting addition : )

Thx.

On Feb 16, 3:46*pm, "Chip Pearson" wrote:
You can use the SelectionChange event procedure of the workbook to detect
when a focus moves to a cell.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
* * If StrComp(Target.Address, "$A$1", vbBinaryCompare) = 0 Then
* * * * ' user selected A1
* * * * ' your code here
* * End If
End Sub

However, if you are not allowing the user to select any cells, locked or
unlocked, this won't work since focus can never be set to a cell. In this
case, have only two options that I can think of. The first is to create a
menu item or commandbar that the user can click to run some code. The other
option is to drop a Forms or OLE button directly on to the worksheet and
attach some code to the button.

Finally, you cannot change the cursor when the user hovers over a cell. You
can change it with VBA code but such code won't be triggered if the cursor
just hovers over, without actually selecting, a cell.

My preference is to always allow the user to select any cells he wants, even
those that are locked. The reason is that the user may use the selection
indicator *and row/column heading colors to highlight cells to make things
easier to read, especially in a large data table.

I guess the bottom line is that you can't really do any of the things you
want to.

--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
* * Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)

"Luke Bailey" wrote in message

...



Hello,


I have a couple of questions on Excel Spreadsheet. *I have a protected
worksheet that does not allow users to select locked or unlocked cells.
Ideally, I would like users to have a cell that when clicked on, runs a
bit
of code. *I thought I could accomplish by inserting a button, then setting
background to opaque and shawdows to false. *This does work, but you can
still see outline off the button (which I do not want). *Any other way to
accomplish this?


I am willing to compromise and let the protection of the form allow users
to
select locked cells if necessary. *But would also like to have the mouse
change to a different pointer when over that cell (which was working with
the
button as well).


Thanks for any ideas!- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Run Code on Cell Select

Thanks Chip!

I went with the Workseet_SelectionChange option and let users select the
unlocked cells - then commented on cell so they know clicking triggers an
event to let the code run and drill down to further level data.

After some thinking about it, users may want to copy and paste areas from
the worksheet into an e-mail, etc. anyways, so works out for the best.

Thanks again!

Luke


"Chip Pearson" wrote:

You can use the SelectionChange event procedure of the workbook to detect
when a focus moves to a cell.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If StrComp(Target.Address, "$A$1", vbBinaryCompare) = 0 Then
' user selected A1
' your code here
End If
End Sub

However, if you are not allowing the user to select any cells, locked or
unlocked, this won't work since focus can never be set to a cell. In this
case, have only two options that I can think of. The first is to create a
menu item or commandbar that the user can click to run some code. The other
option is to drop a Forms or OLE button directly on to the worksheet and
attach some code to the button.

Finally, you cannot change the cursor when the user hovers over a cell. You
can change it with VBA code but such code won't be triggered if the cursor
just hovers over, without actually selecting, a cell.

My preference is to always allow the user to select any cells he wants, even
those that are locked. The reason is that the user may use the selection
indicator and row/column heading colors to highlight cells to make things
easier to read, especially in a large data table.

I guess the bottom line is that you can't really do any of the things you
want to.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

"Luke Bailey" wrote in message
...
Hello,

I have a couple of questions on Excel Spreadsheet. I have a protected
worksheet that does not allow users to select locked or unlocked cells.
Ideally, I would like users to have a cell that when clicked on, runs a
bit
of code. I thought I could accomplish by inserting a button, then setting
background to opaque and shawdows to false. This does work, but you can
still see outline off the button (which I do not want). Any other way to
accomplish this?

I am willing to compromise and let the protection of the form allow users
to
select locked cells if necessary. But would also like to have the mouse
change to a different pointer when over that cell (which was working with
the
button as well).

Thanks for any ideas!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA: Column Select then Data Select then return to cell A1 James C[_2_] Excel Discussion (Misc queries) 3 February 1st 10 11:35 AM
SELECT THE FIRST CELL IN ADVANCE FILTERed worksheet vba code CmK Excel Programming 2 June 10th 07 12:53 PM
Using formulas to select cells (Ex: Select every nth cell in a col Lakeview Photographic Services Excel Discussion (Misc queries) 2 March 15th 07 02:17 PM
Select Until Empty Cell From VBA Code Eric Excel Programming 1 February 11th 05 02:09 PM
Code to Select Row David McRitchie[_2_] Excel Programming 0 September 19th 03 11:02 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"