Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Commandbutton backcolor change on event


Further to my post yesterday, I need to have a commandbutton change its
color when the content of a cell changes in another worksheet from
blank("") to a value

Had the following suggestion from a board member(thanks!)

Private Sub Worksheet_Change(ByVal Target As Range)
Const sAdd As String = "A1" '<<==== CHANGE

If Not Intersect(Range(sAdd), Target) Is Nothing Then
With Me.CommandButton1
If IsEmpty(Target) Then
..BackColor = &HFFFF&
Else
..BackColor = &HFF&
End If
End With
End If

End Sub


This works if I manually enter a value or "" into say"A1" on the sheet,
but not if the value changes in "A1" as a result of a formula - any
ideas welcome!

Also, what do I need to add to the code to say refer to "A1" in another
worksheet??

Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=494302

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Commandbutton backcolor change on event

Hi Peter,

Try:

'===============
Private Sub Worksheet_Calculate()
Const sAdd As String = "A1" '<<==== CHANGE

With ThisWorkbook.Sheets("Button").CommandButton1
If Range(sAdd).Value < "" Then
.BackColor = &HFFFF&
Else
.BackColor = &HFF&
End If
End With
End Sub
'<<===============

This is worksheet event code and should be pasted into the code module of
the sheet which houses the formula cell.

Change"Button" to the name of the sheet which houses the command button.


---
Regards,
Norman


"peter.thompson"
<peter.thompson.205xby_1134786601.7361@excelforu m-nospam.com wrote in
message news:peter.thompson.205xby_1134786601.7361@excelfo rum-nospam.com...

Further to my post yesterday, I need to have a commandbutton change its
color when the content of a cell changes in another worksheet from
blank("") to a value

Had the following suggestion from a board member(thanks!)

Private Sub Worksheet_Change(ByVal Target As Range)
Const sAdd As String = "A1" '<<==== CHANGE

If Not Intersect(Range(sAdd), Target) Is Nothing Then
With Me.CommandButton1
If IsEmpty(Target) Then
BackColor = &HFFFF&
Else
BackColor = &HFF&
End If
End With
End If

End Sub


This works if I manually enter a value or "" into say"A1" on the sheet,
but not if the value changes in "A1" as a result of a formula - any
ideas welcome!

Also, what do I need to add to the code to say refer to "A1" in another
worksheet??

Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile:
http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=494302



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Commandbutton backcolor change on event


Thanks Norman - works fine

Sorry a couple more question

1) If I want to do this for 10 buttons on the same worksheet, what di
In need to do to the code?

2) If the cell is inanother worksheet, again, what needs to change to
code?

Thanks a bunch for hour help

Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=494302

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Commandbutton backcolor change on event

Private Sub Worksheet_Calculate()
Const sAdd As String = "A1" '<<==== CHANGE

With ThisWorkbook.Sheets("Button")
If Worksheets("Sheet22).Range(sAdd).Value < "" Then
.CommandButton1.BackColor = &HFFFF&
.CommandButton2.BackColor = &HFFFF&
.CommandButton3.BackColor = &HFFFF&
.CommandButton4.BackColor = &HFFFF&
.CommandButton5.BackColor = &HFFFF&
.CommandButton6.BackColor = &HFFFF&
.CommandButton7.BackColor = &HFFFF&
.CommandButton8.BackColor = &HFFFF&
.CommandButton9.BackColor = &HFFFF&
.CommandButton10.BackColor = &HFFFF&
Else
.CommandButton1.BackColor = &HFF&
.CommandButton2.BackColor = &HFF&
.CommandButton3.BackColor = &HFF&
.CommandButton4.BackColor = &HFF&
.CommandButton5.BackColor = &HFF&
.CommandButton6.BackColor = &HFF&
.CommandButton7.BackColor = &HFF&
.CommandButton8.BackColor = &HFF&
.CommandButton9.BackColor = &HFF&
.CommandButton10.BackColor = &HFF&
End If
End With
End Sub


--

HTH

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


"peter.thompson"
<peter.thompson.2063cm_1134794401.4674@excelforu m-nospam.com wrote in
message news:peter.thompson.2063cm_1134794401.4674@excelfo rum-nospam.com...

Thanks Norman - works fine

Sorry a couple more question

1) If I want to do this for 10 buttons on the same worksheet, what di
In need to do to the code?

2) If the cell is inanother worksheet, again, what needs to change to
code?

Thanks a bunch for hour help

Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile:

http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=494302



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
CommandButton color change on event peter.thompson Excel Programming 4 December 17th 05 03:30 AM
Change BackColor Steve Excel Programming 1 July 11th 05 04:09 PM
Using A Macro To Add Event Procedure To A CommandButton Donna[_7_] Excel Programming 4 February 23rd 05 02:44 PM
Using A Macro To Add Event Procedure To A CommandButton [email protected] Excel Programming 1 February 21st 05 10:59 AM
Changing backcolor of commandbutton scottnshelly[_21_] Excel Programming 2 April 22nd 04 11:27 PM


All times are GMT +1. The time now is 10:27 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"