#1
|
|||
|
|||
VBA Word : identify empty cell and aply specific format
Hello everyone
Thank you in advance for your help. First of all, sorry for my english, if something ist not clear please ask. I'm a beginner in VBA (and i usually work with excel) System : Windows 10 Version : Word 2019 I have 30+ tables in a word document. I need to select all empty cells an aply a specific format (for example "standard1") The reason : I didn't pay attention to the formats while creating the table, my bad. And now there are many different formats applied to the empty cells. Find and select doesn't work, because the cells are empty. I found this macro (is there a way to twist it the way i need it?) I replace the MsgBox with : Selection.Style = ActiveDocument.Styles("standard1") And it seem to work up to the first cell with text. Sub CheckTableCells() Dim oCell As Cell Dim oRow As Row Dim MyRange As Range For Each oRow In Selection.Tables(1).Rows For Each oCell In oRow.Cells If Selection.Text = Chr(13) & Chr(7) Then oCell.Select MsgBox oCell.RowIndex & " " & oCell.ColumnIndex & " is empty." End If Next oCell Next oRow End Sub I wish a happy new year to everyone, |
#2
|
||||
|
||||
If the style exists in the document, then
Code:
Sub CheckTableCells() Dim oTable As Table Dim oCell As Cell Dim MyRange As Range For Each oTable In ActiveDocument.Tables For Each oCell In oTable.Range.Cells Set MyRange = oCell.Range MyRange.End = MyRange.End - 1 If Len(MyRange) = 0 Then MyRange.Style = ActiveDocument.Styles("standard1") End If Next oCell Next oTable End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Works like a charm.
This saved me a lot of time and it will save me time, as I no longer have to keep track of which format has been applied for each empty cell. Thank you for the quick help Have a nice day. |
Tags |
table, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need formula to format one cell if another cell includes specific text | Bigsur2 | Excel | 2 | 11-17-2022 11:53 AM |
How do I test a cell for a specific word if the cell has a drop down list. | RoehamptonTech | Excel | 1 | 08-23-2017 05:05 AM |
Delete cell content that has a specific format | Daniel Arbeit | Excel Programming | 1 | 06-20-2016 03:02 PM |
Get next non empty cell from a specific list with VBA | chriss17 | Excel Programming | 2 | 06-15-2016 08:40 AM |
Way to identify what image format has been inserted in PPT? | Pantucci | PowerPoint | 1 | 08-20-2010 12:03 AM |