Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2020, 09:58 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Default Changing background colour in table based on value.

Hi there,

I am trying to change the color of some cells in a dropdown menu in a table (word document) I am only a fairly average skilled person when it comes to computers and would really appreciate some help.

I would like the following to have a green shaded background

Independent
Supervised



I would like the following to have a orange shaded background

Assisted

I would like the following to have a red shaded background

Marginal
Dependent

I have attached a clip of the table I have in excel to show you what I mean.. It is perfect but i can not get it into a word document.

Thank you so much in advance
Attached Images
File Type: png Example.PNG (19.7 KB, 39 views)
Reply With Quote
  #2  
Old 09-27-2020, 11:06 PM
Guessed's Avatar
Guessed Guessed is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Have a look at this thread
https://www.msofficeforums.com/word-...selection.html
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 09-27-2020, 11:46 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Default

Thank you so much, I did try that and it certainly works. How do I go in to change the words and also the yellow colour to orange ?
Reply With Quote
  #4  
Old 09-28-2020, 12:05 AM
Guessed's Avatar
Guessed Guessed is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You need to look closely at the code and adapt it to your requirements. I'm not sure exactly which code you chose. Colours can be explicitly defined in RGB terms for more flexibility in defining a colour.

An example which would give you orange is
Code:
Case "Assisted": .Range.Cells(1).Shading.BackgroundPatternColorIndex = RGB(255,192,0)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 09-28-2020, 04:53 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Default

ok thanks... what section do I go into to locate the formula to be able to modify? The code that seemed to work so far is the 'content controls - dropdown conditional formatting.' Thanks again
Reply With Quote
  #6  
Old 09-28-2020, 05:55 PM
Guessed's Avatar
Guessed Guessed is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It appears you are coming from ground zero in terms of using macros. How about you start with this for the basics
Getting to grips with VBA basics in 15 minutes

I would also recommend you watch some youtube videos to get an understanding of what is involved in recording, editing and using VBA with Word. https://www.youtube.com/results?sear...Microsoft+Word

Once you are comfortable with the VBA Editor and basic coding, the code you are looking for will be in the ThisDocument module of the template.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 09-28-2020, 07:15 PM
macropod's Avatar
macropod macropod is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2010
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by amandalee View Post
Thank you so much, I did try that and it certainly works. How do I go in to change the words and also the yellow colour to orange ?
Further down the same thread is more code for changing the font colour: https://www.msofficeforums.com/103931-post21.html

For orange, you could use code like:
Code:
Const wdOrange As Long = 41215
'...
  .Cells(1).Shading.BackgroundPatternColor = wdOrange
  .Font.Color = wdOrange
or simply:
Code:
  .Cells(1).Shading.BackgroundPatternColor = wdColorOrange
  .Font.Color = wdColorOrange
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 09-28-2020, 11:27 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Default Thanks

Thank you
Yes I am sorry, I did declare I am far from a computer wiz
I have attempted a version of both suggestions Version 1 does not change the colour at all and version 2 comes up with an error as attached. I have also attached the document in case it is easier for you to see. I appreciate your time. Amanda
Attached Images
File Type: jpg Attempt 2.jpg (114.8 KB, 32 views)
File Type: jpg Attempt 1.jpg (72.9 KB, 32 views)
Attached Files
File Type: docm New Nursing Performance template.docm (38.3 KB, 15 views)
Reply With Quote
  #9  
Old 09-28-2020, 11:36 PM
macropod's Avatar
macropod macropod is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2010
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You haven't declared the wdOrange constant:
Code:
Const wdOrange As Long = 41215
which should go on a new line after:
Code:
Const StrPwd As String = "abc"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 09-29-2020, 04:57 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Unhappy

Thank you, I have put in the line as you had suggested. The issue I have is that when I use the dropdown menu none of them change the background colour? ie it stays white

it also comes up with the attached error?
Attached Images
File Type: png clip.PNG (42.2 KB, 32 views)
Attached Files
File Type: docm New Nursing Performance template2.docm (36.9 KB, 8 views)
Reply With Quote
  #11  
Old 09-29-2020, 05:29 PM
Guessed's Avatar
Guessed Guessed is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

That End If line needs to move up two lines (after the End With line).

The Title property on your CCs doesn't match the code. Change this line
Case "Lst1", "Lst2"
to
Case "Bondy Scale"

Also note that if you are setting the fill and the text colour to exactly the same colour, you won't be able to see the text. Your original request showed the background as a paler tint of the text colour. Once you have the code working, if you want the text to be visible we may need to ensure the background colour is not on 100% fill - but lets get the colour working first.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #12  
Old 09-29-2020, 07:42 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Default

I have made the changes.. still not successful I'm afraid
Thankyou
Amanda
Attached Images
File Type: png snip3.PNG (44.7 KB, 28 views)
Attached Files
File Type: docm New Nursing Performance template 3.docm (38.6 KB, 6 views)
Reply With Quote
  #13  
Old 09-29-2020, 07:43 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Default

I would be really just as happy to have the font black and just change the background color to green orange and red if that makes it easier?
Reply With Quote
  #14  
Old 09-29-2020, 08:43 PM
Guessed's Avatar
Guessed Guessed is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this code instead. If you want subtle changes in colour to show text on a pastel background you need to use RGB values rather than sticking with limits of the built-in Word variables.
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
  Const StrPwd As String = "abc"
  With ContentControl
    Select Case .Title
      Case "Bondy Scale"
        If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:=StrPwd
        With .Range
          .Cells(1).Shading.Texture = wdTextureNone
          Select Case .Text
            Case "Dependent", "Marginal"
              .Cells(1).Shading.BackgroundPatternColor = RGB(255, 109, 109)
              .Font.Color = wdColorRed
            Case "Assisted"
              .Cells(1).Shading.BackgroundPatternColor = RGB(255, 183, 67)
              .Font.Color = RGB(255, 160, 0)
            Case "Supervised", "Independent"
              .Cells(1).Shading.BackgroundPatternColor = wdColorLightGreen
              .Font.Color = wdColorBrightGreen
            Case Else
              .Cells(1).Shading.BackgroundPatternColor = wdColorWhite
              .Font.ColorIndex = wdAuto
            End Select
          End With
      ActiveDocument.Protect wdAllowOnlyFormFields, True, StrPwd
    End Select
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #15  
Old 09-29-2020, 08:56 PM
amandalee amandalee is offline Changing background colour in table based on value. Windows 10 Changing background colour in table based on value. Office 2013
Novice
Changing background colour in table based on value.
 
Join Date: Sep 2020
Posts: 12
amandalee is on a distinguished road
Smile Thank you

Thank you - that works!! you are amazing!!!
would you help with one last thing please... the table at the top of the document was the original 'Content Controls - Dropdown Conditional Format.docm' however it seems to be protected and i can not delete it from my worksheet. Would you please help me with that?
Attached Files
File Type: docm New Nursing Performance template 4.docm (39.2 KB, 10 views)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Background Word Colour not showing on PDF phorsley Word 1 04-24-2020 09:18 AM
Changing background colour in table based on value. Text Background Colour in a Table Colin Vicary Word 4 08-08-2019 06:02 AM
Word background colour ignores Windows setting wiganken Word 1 07-19-2018 09:25 AM
Changing background colour in table based on value. Changing background colour based on dropdown choice PLeo Word VBA 2 08-03-2017 07:40 AM
Trying to clear the background colour from a theme ezekiel181 Word 1 11-14-2010 07:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:38 AM.


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