Assigning Functions to Toggle Buttons

  • Thread starter Thread starter LUKEMUDGE
  • Start date Start date
L

LUKEMUDGE

I'm trying to make a toggle button change the colour of a cell. I've tried
several variations of the 'IF' function and cannot get it to recognise the
button as a true/false answer to the argument. If anyone can help either with
VB script or an 'IF' argument proceedure that would be fantastic.

Thanks

Luke
 
If Range("A1").Value > 0 Then
Range("B2").Interior.ColorIndex = 3
Else
Range("B2").Interior.ColorIndex = xlNone
End If
 
Assuming you wanted to toggle the cell's color between Red and None, just
use this single line of code in your toggle button's event procedure...

Range("A1").Interior.ColorIndex = -4139 - Range("A1").Interior.ColorIndex

The way to figure out the number (-4139 for my example code) is to add -4142
(the value of xlNone) and the ColorIndex value for the color you want (3
being Red in my example code)...

-4142 + 3 = -4139

Just use the ColorIndex in place of the value 3 in above.
 

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