Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #34  
Old 12-18-2018, 08:15 PM
gmaxey gmaxey is offline Change color according with dropdown selection Windows 10 Change color according with dropdown selection Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Paul,


Not very elegant but one may have to deal with merged cells:

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
  If Len(.Title) < 6 Then Exit Sub
  If Left(.Title, 6) = "Status" Then
    On Error GoTo Err_Merged
    Select Case .Range.Text
      Case "COMPLETE"
        .Range.Rows(1).Shading.BackgroundPatternColorIndex = wdGreen
      Case "Pending": .Range.Rows(1).Shading.BackgroundPatternColorIndex = wdYellow
      Case Else: .Range.Rows(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
    End Select
  End If
End With
lbl_Exit:
  Exit Sub
Err_Merged:
  DealWithMergedCells ContentControl
End Sub

Sub DealWithMergedCells(oCC As ContentControl)
Dim oCellRef As Cell, oCell As Cell
  Set oCellRef = oCC.Range.Cells(1)
  Select Case oCC.Range.Text
    Case "COMPLETE"
      oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex = wdGreen
    Case "Pending"
       oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
    Case Else
       oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
  End Select
  For Each oCell In oCC.Range.Tables(1).Range.Cells
    If oCell.RowIndex = oCellRef.RowIndex Then
      oCell.Shading.BackgroundPatternColorIndex = oCC.Range.Cells(1).Shading.BackgroundPatternColorIndex
    End If
  Next
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
 

Tags
color, dropdown, reaction



Similar Threads
Thread Thread Starter Forum Replies Last Post
block selection in dropdown list Intruder Excel 2 01-10-2013 10:20 AM
Change color according with dropdown selection Dropdown selection value coconutt Word VBA 5 09-13-2012 05:23 PM
Change color according with dropdown selection Change cell color when selection is made from a drop down list fedcco Excel 12 08-28-2012 10:43 PM
Change color according with dropdown selection Autofill a form which is contingent on a dropdown selection. biffle0764 Word 2 05-09-2012 12:54 PM
Change cell color everytime a value is selected in dropdown list angelica_gloria Excel 4 01-27-2012 06:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:54 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft