Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default Cell working as a button? Cell color control

Can I get a cell to work as if it were a button? (Or can I place a button on
a worksheet?)

I have been playing with ActiveCell but have not quite figured how to trigger
it. In VB I could create a Sub Toggle () and run its contents from a button.
Can I program a cell to run a Sub?

Also,: Why doesn't my mouse thumb wheel work when I view code?

And Then: I can change the cell color but how do I change the shade or
crosshatch value using code?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...tions/200708/1

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Cell working as a button? Cell color control

Can I get a cell to work as if it were a button?

Yes. You need to use the worksheet's SelectionChange event, and check the cell against the target.
For example, this code will run the macro CellA1 whenever cell A1 is selected.

'In the sheet's codemodule
'Right-Click the sheet tab and select "View Code",
'then paste in the window that appears
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then
CellA1
Else
NotCellA1
End If
End Sub

'In a regular codemodule
Sub CellA1()
'Turn off events if you do anything to change a cell
'other than its formatting
MsgBox "Howdy from Cell A1"
With Range("A1").Interior
.ColorIndex = 3
.Pattern = xlLightDown
End With
End Sub

Sub NotCellA1()
'Turn off events if you do anything to change a cell
'other than its formatting
MsgBox "Howdy from NOT Cell A1"
With Range("A1").Interior
.ColorIndex = xlNone
.Pattern = xlNone
End With
End Sub



(Or can I place a button on a worksheet?)


Yes you can, and you can assign a macro to it.

And Then: I can change the cell color but how do I change the shade or
crosshatch value using code?


See the code above. Record a macro to get the desired values...

HTH,
Bernie
MS Excel MVP


"Emerogork via OfficeKB.com" <u36894@uwe wrote in message news:77792f0c970c6@uwe...
Can I get a cell to work as if it were a button? (Or can I place a button on
a worksheet?)

I have been playing with ActiveCell but have not quite figured how to trigger
it. In VB I could create a Sub Toggle () and run its contents from a button.
Can I program a cell to run a Sub?

Also,: Why doesn't my mouse thumb wheel work when I view code?

And Then: I can change the cell color but how do I change the shade or
crosshatch value using code?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...tions/200708/1



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
Need a button to click to toggle cell color on/off Tonso Excel Discussion (Misc queries) 2 February 7th 07 01:31 PM
Need a button to click to toggle cell color on/off Tonso Excel Discussion (Misc queries) 1 February 7th 07 12:33 AM
Excel: Syntax to change cell color based on color of another cell davew18 Excel Worksheet Functions 1 January 4th 07 01:24 PM
Excel - create button to replace cell content with cell value blackmot Excel Worksheet Functions 3 December 7th 05 05:10 PM
Adding a control button to insert a date in the active cell. Mike Excel Discussion (Misc queries) 2 February 15th 05 06:27 PM


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

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

About Us

"It's about Microsoft Excel"