Excel Command Button Color

  • Thread starter Thread starter justbrewit
  • Start date Start date
J

justbrewit

Suppose I have a spreadsheet that does a number of calculations. I hav
a command button which I use to execute the solutions.

1. I would like the button to turn green (or some color) when th
solution has converged, which I can check at any time

2. If a change to any parameter is made (and thus the former solutio
is not a solution for the new case) I would like to change the color
to red for example.

i would appreciate it if someone could help me figure out how t
accomplish this, particularly the second part.


Thank yo
 
if the solution is arrived at through iterative calculations in a single
calculation event, then you can not take actions inside that event.

If you code performs the calculations, then just add code to color the
button based on the conditions within your code.
 
This is fairly straight forward if you use VBE and a User Defined Form.
Is that the case or are you using the buttons from the worksheet tool?
 
Option Explicit
Private Sub CommandButton1_Click()
'your code to do all the work here
if somethinggoodhappened = true then
Me.CommandButton1.BackColor = &HFF00&
else
me.commandbutton1.backcolor = &HFF&
end if
End Sub
 
Thanks for the help, but I am not sure that I am being totally clear.

After I run the VB code and find a solution to my equations, can I
(somehow) change the button color if any cell in the workbook is
modified by the user?
 
If any cell is changed in the workbook????

This code goes behind the ThisWorkbook module:

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Me.Worksheets("sheet2").OLEObjects("commandbutton1").Object.BackColor _
= &HFF&
End Sub

Change the sheet name and the commandbutton name to match.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top