Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2022, 07:44 AM
Denalei Denalei is offline VBA Word : identify empty cell and aply specific format Windows 10 VBA Word : identify empty cell and aply specific format Office 2019
Novice
VBA Word : identify empty cell and aply specific format
 
Join Date: Jan 2022
Posts: 2
Denalei is on a distinguished road
Default 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,
Reply With Quote
  #2  
Old 01-04-2022, 10:06 PM
gmayor's Avatar
gmayor gmayor is offline VBA Word : identify empty cell and aply specific format Windows 10 VBA Word : identify empty cell and aply specific format Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 01-05-2022, 12:41 AM
Denalei Denalei is offline VBA Word : identify empty cell and aply specific format Windows 10 VBA Word : identify empty cell and aply specific format Office 2019
Novice
VBA Word : identify empty cell and aply specific format
 
Join Date: Jan 2022
Posts: 2
Denalei is on a distinguished road
Default

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

Tags
table, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Word : identify empty cell and aply specific format 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
VBA Word : identify empty cell and aply specific format Delete cell content that has a specific format Daniel Arbeit Excel Programming 1 06-20-2016 03:02 PM
VBA Word : identify empty cell and aply specific format Get next non empty cell from a specific list with VBA chriss17 Excel Programming 2 06-15-2016 08:40 AM
VBA Word : identify empty cell and aply specific format Way to identify what image format has been inserted in PPT? Pantucci PowerPoint 1 08-20-2010 12:03 AM

Other Forums: Access Forums

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