+ Reply to Thread
Results 1 to 26 of 26

how to fill specific colors of combo box depending on its text values

  1. #1
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    how to fill specific colors of combo box depending on its text values

    hi,

    i have a little background in VBA and i'm having difficulty in creating a code that will make a combo box(on active x control) filled with colors red,orange,green for each specific texts "open", "provisional close", "close". thanks in advance...

    -eric

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: how to fill specific colors of combo box depending on its text values

    Hi, welcome to the forum.
    Could you be more specific. I do not quite understand what it is actually you require.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    hi Keebellah,

    basically i just want a combox filled with different color per different selection just like this. what's the VB code for this? thanks

    Screenshot-2016-06-12_07.25.51.png

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: how to fill specific colors of combo box depending on its text values

    The items in a combo box's list will all have the same formatting, color, font, size, underline etc.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    hi Mikerickson,

    is there a way that i can customize them thru vba codes? so when you select "open" it will be filled with red, "provisional close" would be filled with orange and "close" will be filled with green??

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: how to fill specific colors of combo box depending on its text values

    No. One cannot customize comboxboxes or list boxes to accept rich text (varying formats).

    But I just had a thought. You could use the control's GotFocus event to show three appropriately colored command buttons.
    Last edited by mikerickson; 06-11-2016 at 11:01 PM.

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: how to fill specific colors of combo box depending on its text values

    Not with ActiveX not, but yes with the form combobox
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    hi Keebelah,

    Thanks! this is what i actually want.. but how will i implement this on succeeding combo box? will i copy the code for combo box2,3,4, and so on...?? i'll be using this on a checklist that's why i will be using the combo box per checklist item. thanks a lot again..

    -eric

  9. #9
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    hi??

    anyone who knows to implement this codes on multiple combo box? should i copy-paste it per combo box?

    thanks,
    -eric

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to fill specific colors of combo box depending on its text values

    eric

    If you have multiple ActiveX (it's an ActiveX combobox not a Forms combobox in the workbook Keeballah uploaded) you could have a separate sub to do the formatting.

    This sub would be passed the combobox that's just been changed.

    It would look something like this and be in a standard module.
    Please Login or Register  to view this content.
    It would be called like this from each combobox's change event.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  11. #11
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    hi Norie,

    sorry i don't get where to paste those code when i open the VBA on excel. does the first code must be inserted in a module or will be paste also on the worksheet together with the 2nd code??

    thanks
    -eric

  12. #12
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    hi norie,

    here's what i did, i insert the first code on a module then paste the 2nd code in the worksheet that i'm working but still it doesn't work. have you tried this on your excel file?

    thanks
    -eric

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to fill specific colors of combo box depending on its text values

    It works for me, though I did change the code to change the font colour rather than the fill colour.

    Any chance you could upload the workbook you tried the code in?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  14. #14
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    i don't want to change the font color, i rather need that the background color will change every time the selection is made.
    here's the sample file that i have worked with.
    Attached Files Attached Files

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to fill specific colors of combo box depending on its text values

    Your comboboxes aren't populate with anything.

    Try setting the ListFillRange of each combox to 'options' and change the code for FormatCombo to this.
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    i'm getting near.. i want the provisional open to be colored with orange but the "vbOrange" display black color, is there something wrong with my code "vbOrange"?

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to fill specific colors of combo box depending on its text values

    There is no vbOrange.

  18. #18
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: how to fill specific colors of combo box depending on its text values

    That is what my frist code did too.
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    i'm getting near... i want the provisional open to be back color with orange, why does "vbOrange" code doesn't work? it only displays black background color.

  20. #20
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    then what is the correct code for orange color?

  21. #21
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: how to fill specific colors of combo box depending on its text values

    Fill B1 with an orange color that you like, then run this code

    Please Login or Register  to view this content.

  22. #22
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: how to fill specific colors of combo box depending on its text values

    Quote Originally Posted by Norie View Post
    There is no vbOrange.
    There is a constant xlrgbOrange.

  23. #23
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: how to fill specific colors of combo box depending on its text values

    Mike

    Never knew there were xlRGB constants.

  24. #24
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: how to fill specific colors of combo box depending on its text values


  25. #25
    Registered User
    Join Date
    01-22-2015
    Location
    philippines
    MS-Off Ver
    MS 2013
    Posts
    17

    Re: how to fill specific colors of combo box depending on its text values

    i think i'm all set now, thanks for the help guys Keebellah, Norie, Mikerickson for the help I appreciate it so much
    here's the final code:

    paste in module
    Sub FormatCombo(cb As MSForms.ComboBox)
    With cb
    Select Case .Value
    Case Is = "Open"
    .BackColor = vbRed
    Case Is = "Provisional Close"
    .BackColor = rgbDarkOrange
    Case Is = "Close"
    .BackColor = vbGreen
    Case Else
    .BackColor = vbWhite
    End Select
    End With
    End Sub


    paste in worksheet
    Private Sub ComboBox1_Change()
    FormatCombo ComboBox1
    End Sub
    Private Sub ComboBox2_Change()
    FormatCombo ComboBox2
    End Sub
    Private Sub ComboBox3_Change()
    FormatCombo ComboBox3
    End Sub



    the simpler the code the better. thanks again.

    -Eric

  26. #26
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: how to fill specific colors of combo box depending on its text values

    I agree, the simpler the better
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Determine if meeting a specific goal? with FILL colors
    By michaelDDW in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-09-2015, 06:50 PM
  2. Replies: 16
    Last Post: 12-12-2014, 06:19 AM
  3. Combo Box - GO TO specific cell depending on value in list
    By ScottBeatty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-05-2014, 01:21 PM
  4. Combo Box - GO TO specific cell depending on value in list
    By ScottBeatty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2014, 10:39 AM
  5. [SOLVED] Fill combo box list based on other combo box values
    By rain4uu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2013, 03:04 PM
  6. my VBA can't fill in the specific cells with colors
    By kwfine in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-29-2012, 12:01 PM
  7. Excel 2007 : how do you count cells with specific fill colors
    By FluidicAztec in forum Excel General
    Replies: 2
    Last Post: 07-16-2008, 04:51 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1