PDA

View Full Version : Conditional Formatting with command button



DIStudio
07-18-2008, 06:13 AM
I am trying to highlight 4 specific cells from an excel spreadsheet when a command button is clicked. I am currently able to use conditional formatting to do that cell by cell but I need to be able to do this by the click of a command button on the worksheet.

For example:

I have a command button which is labeled Cabela.
When that button is clicked I need cells B8, B9, K8 and K9 to highlight green.

Any suggestions? Thank you so much for your help!

Bob Phillips
07-18-2008, 06:16 AM
Assuming that it is a Format toolbar button, and you have assigned a macro called FormatCells to that button



Public Sub FormatCells()

Range("B8:B9, K8:K9").Interior.ColorIndex = 10

End Sub

DIStudio
07-18-2008, 06:26 AM
Thank you for your quick response!

I have one more question ... am I able to place the button "Cabela" built in VBA into a cell in Excel?

Thanks!

Bob Phillips
07-18-2008, 06:32 AM
You will need to explain that again, it isn't clear what you mean.

DIStudio
07-18-2008, 06:52 AM
In my excel spread sheet I need to highlight different cells based upon different vehicle descriptions which are listed in column V. I have for example Cabela(V2) and Chrome(V3).

I need to have a clickable button on my excel spreadsheet for each of those.

When I click on cell V2(Cabela) I need cells B8, B9, K8 and K9 to highlight green - as you have showed me.
THEN when I click on cell V3(Chrome) I need all the cells to clear and have cells B6:B9, G6:G9, K6:K9, O6:O9 highligh in yellow.

Bob Phillips
07-18-2008, 07:04 AM
Okay, I think I get it. Hopefully this is it



Public Sub FormatCells()

With ActiveCell

If .Address = "$V$2" Then

Range("B8:B9, K8:K9").Interior.ColorIndex = 10

ElseIf .Address = "$V$3" Then
Range("B6:B9, G6:G9, K6:K9, O6:O9").Interior.ColorIndex = 6
End If
End With
End Sub