#1
|
|||
|
|||
Macro to shade empty cells in table with pattern
Hi,
I am looking for assistance in creating a macro that will shade empty cells in the second table of my document with the pattern "Lt Up Diagonal" and color adjusting automatically. My table has 5 columns and 29 rows (rows not fixed). I should also note that I have a macro that will completely remove rows with empty 3, 4 and 5 cells. I tried another macro from a thread I found here, but I'm struggling with adjusting it to my needs. Below are previews of what I have (left) vs. what I want to achieve (right). |
#2
|
|||
|
|||
An empty table cell isn't empty as it contains an end of cell mark which is a compound character with a text length of two characters. The routine below simply loops through the table checking the text length of each cell and applies the texture as necessary
Code:
Sub ApplyTableShading() Dim tbl As Table: Set tbl = ActiveDocument.Tables(2) Dim tRow As Row, tCell As Cell For Each tRow In tbl.Rows For Each tCell In tRow.Cells If Len(tCell.Range.Text) = 2 Then tCell.Shading.Texture = wdTextureDiagonalUp Next tCell Next tRow End Sub |
#3
|
|||
|
|||
Hi Italophile,
Thank you for your help, much appreciated! The code works great, although it didn't recognize the numbering in the first column, but that's ok I worked it out |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
deleting a row in word table if a certain number of cells are empty and/or contain a certain value | Atuck88 | Word VBA | 3 | 01-06-2022 01:47 AM |
Conditionally Shade Table Cells | S7ewie | Mail Merge | 8 | 04-29-2021 01:52 AM |
How can i upload values of Non-Empty Cells Reference of a Table in ComboBox | SamDsouza | Word VBA | 4 | 03-08-2021 10:00 PM |
Macro to delete rows with all empty cells | ubns | Excel Programming | 2 | 08-14-2012 02:01 AM |
Apparently empty (blank) cells aren't empty | daymaker | Excel | 3 | 03-08-2012 03:41 PM |