Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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 Productivity Tools

shot kutools word kutools tab 1180x121
shot kutools word kutools plus tab 1180x120
 

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

  • Complicated and repeated operations can be done a one-time processing in seconds.
  • Insert multiple images across folders into Word document at once.
  • Merge and combine multiple Word files across folders in to one with your desired order.
  • Split the current document into separate documents according to heading 1, 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...
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Raj · 17 days ago
    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?
  • To post as a guest, your comment is unpublished.
    Patti · 2 months ago
    Could I modify this code to have it highlight any drop down choice without listing all of them out?
  • To post as a guest, your comment is unpublished.
    Shannon · 3 months ago
    Hi, Thank you for this. Is there a way of only changing the text color and not the entire cell?
    • To post as a guest, your comment is unpublished.
      skyyang · 3 months ago
      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
      • To post as a guest, your comment is unpublished.
        Bryan Rantala · 2 months ago
        Struggling here to apply this as a style rather than a color or shade.
  • To post as a guest, your comment is unpublished.
    mark · 5 months ago
    Could I enter custom colors? (rgb)
  • To post as a guest, your comment is unpublished.
    Paul · 5 months ago
    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'