#1
|
|||
|
|||
How to color the specific cells at once?
Hi,
I have a long table with thousands of cells, some cells should apply background colors, in my case; the cells have a word inside themselves (like Name) and I'd like to give a color to them immediately, rather than select one by one and apply color. |
#2
|
|||
|
|||
Simplest method - won't give cell color, but rather word color.
Use Replace to find the target word and replace with the same word applying color and/or text shading. You can get to the formatting options by clicking More on the Replace dialog. Anything else will require a macro. If you want a volunteer here to write a macro for you, I would suggest that you attach a sample file so they will not have to try to recreate your situation to give you a fix. |
#3
|
|||
|
|||
Something I considered - could you do the entire table in Excel, where you can use conditional formatting? There's a pre-set condition that says "cell contains text" that would work even if your condition were "apple" and you had "applesauce" and "crabapple" options, or the like. The tricky part is getting a loooong Excel table into a Word document, if indeed it needs to go back to being a Word doc. You could insert an Excel sheet into Word, but getting it to paginate across multiple pages is not something I've been able to do neatly. But if you create it in Excel and "plain" paste it into Word, it becomes a table and in my quick experimenting, it does retain the cell background colors. I just had to make it fit and repeat the header row, etc.
|
#4
|
|||
|
|||
Try this macro (created by AI):
Code:
Sub ShadeCellsInTable() Dim selectedRange As Range Dim tbl As Table Dim cell As Cell Dim findText As String Dim alertMessage As String ' Set the text you want to find findText = "Name" ' Set the alert message alertMessage = "Please select a table." ' Check if a range is selected If Selection.Type <> wdSelectionIP Then Set selectedRange = Selection.Range ' Check if the selection is a table If selectedRange.Tables.Count > 0 Then Set tbl = selectedRange.Tables(1) ' Loop through each cell in the table For Each cell In tbl.Range.Cells ' Check if the cell contains the find text If InStr(cell.Range.Text, findText) > 0 Then ' Shade the cell if it contains the find text cell.Shading.BackgroundPatternColor = wdColorGray25 End If Next cell Else ' Show an alert if a table is not selected MsgBox alertMessage, vbInformation, "Word Macro" End If Else ' Show an alert if a range is not selected MsgBox alertMessage, vbInformation, "Word Macro" End If End Sub |
Tags |
cell color, color, table cell |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Remove highlight with specific color | rekent | Word VBA | 2 | 08-01-2020 10:59 AM |
How can I transfer specific data from email to specific excel cells? | Mauro | Outlook | 1 | 11-11-2019 09:17 PM |
Color in cells | Stefaan1973 | Excel | 2 | 08-13-2018 06:26 AM |
Linking Specific text fields in PP to specific cells in an Excel table | GWRW1964 | PowerPoint | 0 | 02-26-2018 07:37 AM |
Need cells to autofill with color | Silver Rain 007 | Excel | 1 | 10-22-2009 08:19 PM |