Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2024, 08:34 AM
George24 George24 is offline Macro to shade empty cells in table with pattern Windows 11 Macro to shade empty cells in table with pattern Office 2021
Novice
Macro to shade empty cells in table with pattern
 
Join Date: Jan 2024
Posts: 6
George24 is on a distinguished road
Default 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).
Attached Images
File Type: jpg now.JPG (23.5 KB, 8 views)
File Type: jpg want.JPG (34.8 KB, 8 views)
Reply With Quote
  #2  
Old 01-17-2024, 09:03 AM
Italophile Italophile is online now Macro to shade empty cells in table with pattern Windows 11 Macro to shade empty cells in table with pattern Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

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
Reply With Quote
  #3  
Old 01-18-2024, 05:30 AM
George24 George24 is offline Macro to shade empty cells in table with pattern Windows 11 Macro to shade empty cells in table with pattern Office 2021
Novice
Macro to shade empty cells in table with pattern
 
Join Date: Jan 2024
Posts: 6
George24 is on a distinguished road
Default

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
Reply With Quote
Reply



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
Macro to shade empty cells in table with pattern 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 shade empty cells in table with pattern 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:49 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