Note: The other languages of the website are Google-translated. Back to English

How to insert color coded drop down list in Word table?

Supposing, I have a table in my Word document, and now, I want to insert color coded drop down list in a column of the table. It means when I select one option from the drop down, the cell color becomes red, and when I select another option in the drop down, the cell color becomes green as following screenshot shown. How could you solve this job in Word document?

doc color coded drop down

Insert color coded drop down list in Word document with VBA code


Insert color coded drop down list in Word document with VBA code

The following steps can help you to finish this task as you need, first, insert the drop down list, and then apply the color for the drop down. Please do as this:

1. Select a cell in the table where you want to insert the drop down, and then click Developer > Drop-Down List Content Control icon, see screenshot:

doc color coded drop down 1

2. The drop down is inserted into the specific cell, and then click Developer > Properties, see screenshot:

doc color coded drop down 2

3. In the Content Control Properties dialog box, please do the following operations:

(1.) Enter the title name into the Title text box;

(2.) Click Add button go to the Add Choice dialog;

(3.) In the Add Choice dialog, type the drop down list item into the Display Name text box.

doc color coded drop down 3

4. Repeat the Step 3 to insert other drop down list items as you need.

5. After creating the first drop down list, you can copy and paste it to other cells as you need. See screenshot:

doc color coded drop down 4

6. Then you should apply a VBA code, please hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

7. In the Microsoft Visual Basic for Applications window, double click ThisDocument from the Project-Project pane to open the mode, and then copy and paste the following code into the blank module.

VBA code: Insert color coded drop down list into table of a Word document:

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
    If ContentControl.Title = "Status" Then
        Select Case .Text
            Case "Complete"
                .Cells(1).Shading.BackgroundPatternColor = wdColorRed
            Case "In Progress"
                .Cells(1).Shading.BackgroundPatternColor = wdColorGreen
            Case "Not Start"
                .Cells(1).Shading.BackgroundPatternColor = wdColorBlue
            Case Else
                .Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
        End Select
    End If
End With
End Sub

doc color coded drop down 5

Note: In the above code, Status is the title name when you creating the drop down list, and Complete, In Progress, Not Start are the items of the drop down list, you can change them to your own. And you can also change the color to your need.

8. Then save and close the code window, now, when you select one item from the drop down list, its relative color will be filled with the cell, see screenshot:

doc color coded drop down


 


Recommended Word Productivity Tools

 

Kutools For Word - More Than 100 Advanced Features For Word, Save Your 50% Time

  • Complicated and repeated operations can be done one-time processing in seconds.
  • Insert multiple images across folders into Word document at once.
  • Merge and combine multiple Word files across folders into one with your desired order.
  • Split the current document into separate documents according to heading, section break or other criteria.
  • Convert files between Doc and Docx, Docx and PDF, collection of tools for common conversions and selection, and so on...

 

Comments (50)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
When I exit and reopen the program, I have to reenter the VBA code. How do I make it so that it saves?
This comment was minimized by the moderator on the site
Hello,
To save the vba code when opening the file next time, you should save the word file as Word Macro-Enabled Document format. Please try it, hope it can help you!
This comment was minimized by the moderator on the site
Hi there I have just successfully created the drop down list and colours as advised. i have tried to add a further row so i have 4 vs 3 drop downs. I cut and pasted and changed but no colour shows when i select this option, any ideas how to fix?
This comment was minimized by the moderator on the site
Hello, Peter,
First, you should create the drop down list into the table, and then *** your fourth drop down text into the code as below:

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
If ContentControl.Title = "Status" Then
Select Case .Text
Case "Complete" 'First drop down item
.Cells(1).Shading.BackgroundPatternColor = wdColorRed
Case "In Progress" 'Second drop down item
.Cells(1).Shading.BackgroundPatternColor = wdColorGreen
Case "Not Start" 'Third drop down item
.Cells(1).Shading.BackgroundPatternColor = wdColorBlue
Case "New Task" 'Fourth drop down item
.Cells(1).Shading.BackgroundPatternColor = wdColorYellow
Case Else
.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
End Select
End If
End With
End Sub


Please try, hope it can help you!
This comment was minimized by the moderator on the site
this worked grate! Thanks. I tried to apply same code to another drop down content box in same document and I'm having trouble. Don't know how to get tweo in the VBA window. I get 'compile error, Ambiguous name detected: Document_ContentControlOnExit'
This comment was minimized by the moderator on the site
Could I enter custom colors? (rgb)
This comment was minimized by the moderator on the site
Hi, Thank you for this. Is there a way of only changing the text color and not the entire cell?
This comment was minimized by the moderator on the site
Hi, Shannon,
To change the text color instead of the background color, the below VBA code can help you, please try it, hope it can help you!

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
If ContentControl.Title = "Status" Then
Select Case .Text
Case "Complete"
.Cells(1).Range.Font.Color = wdColorRed
Case "In Progress"
.Cells(1).Range.Font.Color = wdColorGreen
Case "Not Start"
.Cells(1).Range.Font.Color = wdColorBlue
Case Else
.Cells(1).Range.Font.Color = wdColorAutomatic
End Select
End If
End With
End Sub
This comment was minimized by the moderator on the site
Struggling here to apply this as a style rather than a color or shade.
This comment was minimized by the moderator on the site
Could I modify this code to have it highlight any drop down choice without listing all of them out?
This comment was minimized by the moderator on the site
Instead of colors, could we use symbols? like if 'completed' display symbol with character code 252, if not started then symbol with character code 88 etc. can you share the vba code using symbols as display plz?
This comment was minimized by the moderator on the site
Hi, this is fantastic! Is there a way to choose from lots of colours?
This comment was minimized by the moderator on the site
Hi, Sam,
To apply more color you like, you should use the below code, and change the RGB color to your need:

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
    If ContentControl.Title = "Status" Then
        Select Case .Text
            Case "Complete"
                .Cells(1).Shading.BackgroundPatternColor = RGB(255, 0, 0)
            Case "In Progress"
                .Cells(1).Shading.BackgroundPatternColor = RGB(0, 255, 64)
            Case "Not Start"
                .Cells(1).Shading.BackgroundPatternColor = RGB(0, 0, 255)
            Case Else
                .Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
        End Select
    End If
End With
End Sub


Please try, hope it can help you!
This comment was minimized by the moderator on the site
Can I color the entire corresponding row instead of just a cell?
This comment was minimized by the moderator on the site
Hello, Jericho,
The below code can help you to deal with your problem, please try it:(You can set the RGB color to your need)

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
If ContentControl.Title = "Status" Then
Select Case .Text
Case "Complete"
.Rows.Shading.BackgroundPatternColor = RGB(255, 0, 0)
Case "In Progress"
.Rows.Shading.BackgroundPatternColor = RGB(0, 255, 64)
Case "Not Start"
.Rows.Shading.BackgroundPatternColor = RGB(0, 0, 255)
Case Else
.Rows.Shading.BackgroundPatternColor = wdColorAutomatic
End Select
End If
End With
End Sub
This comment was minimized by the moderator on the site
Hi, awesome!!! But is there a way to change the color / text of another cell in the same row but in different column? For example: instead of changing the background of "Complete", change the background of "Project-001" . Help me please. Thanks in advance
This comment was minimized by the moderator on the site
Hi, Jaimes,
To solve your problem, please apply the below code:
Note: In the code,the number 1 in the script Cells(1) is the column number of the table, you can chnage it tou your need.

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
If ContentControl.Title = "Status" Then
Select Case .Text
Case "Complete"
.Rows(1).Cells(1).Shading.BackgroundPatternColor = wdColorRed
Case "In Progress"
.Rows(1).Cells(1).Shading.BackgroundPatternColor = wdColorGreen
Case "Not Start"
.Rows(1).Cells(1).Shading.BackgroundPatternColor = wdColorBlue
Case Else
.Rows(1).Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
End Select
End If
End With
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Hello, is there a way to do multiple color-coded drop downs within one document? Thank you!
This comment was minimized by the moderator on the site
Thank you so much for sharing this! However, I'm running into a weird quirk. Sometimes, when I select an item from a drop-down menu and then click elsewhere in the document for it to apply the formatting, it does not work. It selects the proper word from the drop-down menu, but it just stays normal, black text. I have to undo back to before I selected anything, re-select the item from the drop-down menu, and then ONLY click in another drop-down menu to get the formatting to apply. Any ideas on why it's doing this and how I can fix it?
This comment was minimized by the moderator on the site
Hi, I've followed the steps a few times over but the colours don't appear at all?
This comment was minimized by the moderator on the site
Thank you for providing this it is so helpful! However I have come across a bug. When I create a new row in the table below a cell which has had the Drop Down list, it copies the colour of the above cell into this cell without the Drop Down List. If I then copy and paste the drop down list and change the option, it does not change the colour of the cell. Can anyone help?
This comment was minimized by the moderator on the site
Hello,

I tried to create two color code drop down lists in one Word template, however, I get an error message saying 'Ambiguous name detected: Document_ContentControON EXIT. Could you please inform me what I have done wrong?




Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)

With ContentControl.Range

If ContentControl.Title = "Corrective action" Then

Select Case .Text

Case "Corrective action necessary"

.Cells(1).Shading.BackgroundPatternColor = wdColorRed

Case "No further action needed"

.Cells(1).Shading.BackgroundPatternColor = wdColorGreen

Case "Corrective action recommended"

.Cells(1).Shading.BackgroundPatternColor = wdColorYellow

Case Else

.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic

End Select

End If

End With

End Sub

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)

With ContentControl.Range

If ContentControl.Title = "Corrective action for cd" Then

Select Case .Text

Case "Use a new Cd curve"

.Cells(1).Shading.BackgroundPatternColor = wdColorRed

Case "Use an existing Cd curve"

.Cells(1).Shading.BackgroundPatternColor = wdColorGreen

Case "Check the setting and Probe"

.Cells(1).Shading.BackgroundPatternColor = wdColorYellow

Case Else

.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic

End Select

End If

End With


Many thanks in advance for your support.
This comment was minimized by the moderator on the site
Hello - thanks very much for this. How do I incorporate code to change the font color based on selection from drop down list.
This comment was minimized by the moderator on the site
the originally post code worked great but i want to *** it to another drop down box, when i try and *** the same code to VB with a change to the value in the "status" section of the following line:
If ContentControl.Title = "Status" Then
it does not work?
This comment was minimized by the moderator on the site
Hello, joni,If there are two or more tables of drop down lists, you just need to copy and paste the below code into the original code, and change the text reference to your need.
If ContentControl.Title = "Status" Then
Select Case .Text
Case "Complete"
.Cells(1).Shading.BackgroundPatternColor = wdColorRed
Case "In Progress"
.Cells(1).Shading.BackgroundPatternColor = wdColorGreen
Case "Not Start"
.Cells(1).Shading.BackgroundPatternColor = wdColorBlue
Case Else
.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
End Select
End If


The complete code should be this:<div data-tag="code">Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
If ContentControl.Title = "Status" Then
Select Case .Text
Case "Complete"
.Cells(1).Shading.BackgroundPatternColor = wdColorRed
Case "In Progress"
.Cells(1).Shading.BackgroundPatternColor = wdColorGreen
Case "Not Start"
.Cells(1).Shading.BackgroundPatternColor = wdColorBlue
Case Else
.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
End Select
End If
If ContentControl.Title = "Name" Then
Select Case .Text
Case "Lucy"
.Cells(1).Shading.BackgroundPatternColor = wdColorOrange
Case "Skyyang"
.Cells(1).Shading.BackgroundPatternColor = wdColorYellow
Case "Ruby"
.Cells(1).Shading.BackgroundPatternColor = wdColorBlue
Case Else
.Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
End Select
End If
End With
End SubPlease try, hope it can help you!
This comment was minimized by the moderator on the site
This worked fantastic, thank you for your help.
I am also try to figure out a method for the following:
I have two cells that have a numerical value. In a separate celI i want to multiply these values, if the result falls within three set numerical ranges i would like the cell to display text based on the range values.
If the risk severity of a hazard is 3
This comment was minimized by the moderator on the site
This was super helpful and I implemented it successfully. I'm wondering how I can also change the text colour on the same row I have already changed the background colour. Eg. the background row colour is red, but I want the text to be white not black?
This comment was minimized by the moderator on the site
Awesome instruction - worked perfectly! Thank you!
This comment was minimized by the moderator on the site
Hello,
Can you color code the next column, instead of the drop-down list column? For example, no color code in "Status" column (just choices), but color code in adjacent column? Thanks.
This comment was minimized by the moderator on the site
I can get the colours to work with the dropdown list but only after clicking the "status" tag.  Can the staus tag dissapear? As I think it doesnt look nice when the document is completed
There are no comments posted here yet
Load More

Follow Us

Copyright © 2009 - www.extendoffice.com. | All rights reserved. Powered by ExtendOffice. | Sitemap
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
Protected by Sectigo SSL