Consulting

Results 1 to 6 of 6

Thread: Conditional Formatting with command button

  1. #1

    Conditional Formatting with command button

    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!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Assuming that it is a Format toolbar button, and you have assigned a macro called FormatCells to that button

    [vba]

    Public Sub FormatCells()

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

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You will need to explain that again, it isn't clear what you mean.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    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.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Okay, I think I get it. Hopefully this is it

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •