Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-19-2022, 02:15 AM
oddworld oddworld is offline Find Text - traffic light cell background color Mac OS X Find Text - traffic light cell background color Office 2021
Novice
Find Text - traffic light cell background color
 
Join Date: Apr 2022
Posts: 5
oddworld is on a distinguished road
Default Find Text - traffic light cell background color

Hi all, I have a word document that contains multiple tables, within the tables, there is a tolerance column that contains a text value - "Green, Amber or Red".

I am using the below code to find the above-mentioned text and change the cell backgrounds colour to match the text .e. Green text = Green background and so on.

I would appreciate some assistance with two issues:
1. merge the three codes into one, and


2. tweak the Amber code as there is no value for "wdOrange" for Amber text. This procedure clearly doesn't run as-is.


[Sub GreenText()

Dim r As Range
Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:="Green", MatchWholeWord:=True, Forward:=True) = True
r.Cells(1).Shading.BackgroundPatternColorIndex = wdGreen
Loop

End With

End Sub]


[Sub AmberText()

Dim r As Range
Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:="Amber", MatchWholeWord:=True, Forward:=True) = True
r.Cells(1).Shading.BackgroundPatternColorIndex = wdOrange
Loop

End With

End Sub]

[Sub RedText()

Dim r As Range
Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:="Red", MatchWholeWord:=True, Forward:=True) = True
r.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
Loop

End With

End Sub]



Appreciate any assistance
Reply With Quote
  #2  
Old 04-19-2022, 03:13 AM
oddworld oddworld is offline Find Text - traffic light cell background color Mac OS X Find Text - traffic light cell background color Office 2021
Novice
Find Text - traffic light cell background color
 
Join Date: Apr 2022
Posts: 5
oddworld is on a distinguished road
Default

So for the sub AmeberText() wd=Orange i have tweaked my original code to:

[Sub AmberText()
Const wdOrange As Long = 41215
Dim r As Range

Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:="Amber", MatchWholeWord:=True, Forward:=True) = True
r.Cells(1).Shading.BackgroundPatternColor = wdOrange
.Font.Color = wdOrange
Loop

End With

End Sub]

It will only colour the 1st "Amber" cell background to orange then it stops, any ideas on how to tweak it to change all the text Ambers the entire document?
Reply With Quote
  #3  
Old 04-19-2022, 03:40 AM
oddworld oddworld is offline Find Text - traffic light cell background color Mac OS X Find Text - traffic light cell background color Office 2021
Novice
Find Text - traffic light cell background color
 
Join Date: Apr 2022
Posts: 5
oddworld is on a distinguished road
Default

Solved it - Just removed the one from the r.cells(1).shading.BackgroundPatternColor = wdOrange row.

[Sub AmberText()

Dim r As Range, wdOrange As Long
wdOrange = 41215
Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:="Amber", MatchWholeWord:=True, Forward:=True) = True
r.Cells.Shading.BackgroundPatternColor = wdOrange
Loop
End With

End Sub]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Text - traffic light cell background color Cell text color vs cell background color AC PORTA VIA Excel Programming 4 12-19-2018 04:01 PM
Allow Cell Background Fill/Text Color Change while Protected Sheets are Grouped RaudelJr Excel 5 04-18-2017 11:11 PM
Traffic light help needed wmedjaxnjr Excel 1 04-08-2016 09:04 AM
Find Text - traffic light cell background color VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color jc491 Word VBA 8 09-30-2015 06:10 AM
Find Text - traffic light cell background color Cell Background Color: Base it on Content of Cell? tatihulot Excel 4 08-14-2013 03:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:35 PM.


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