Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 91
  • Last Modified:

Run macro on tables where specific cells are blank.

Dear Experts,

can somebody help me re-write this code so that ...
... only tables get worked on where the 2nd and 3nd cell in the first row are blank, i.e. Cell(Row:=1;Column:=2) and Cell(Row:=1;Column:=3) are blank.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub Format_First_Row_All_Tables

Dim tbl as table

For Each tbl In ActiveDocument.Tables
        With tbl.rows.First
            .Range.Font.Name = "Verdana"
            .Range.Font.Size = 7.5
            .Range.Font.Bold = True
            .Shading.BackgroundPatternColor = wdColorGray25
            .HeadingFormat = True
            .HeightRule = wdRowHeightAtLeast
            .Height = CentimetersToPoints(0.9)
        End With
 Next tbl

End Sub

Open in new window

0
AndreasHermle
Asked:
AndreasHermle
1 Solution
 
GrahamSkanCommented:
I think the easiest way is to check the length of the cell ranges. The length of the range of an empty cell is 2.
Sub Format_First_Row_All_Tables()

Dim tbl As Table

For Each tbl In ActiveDocument.Tables
    If Len(tbl.Cell(1, 2).Range) + Len(tbl.Cell(1, 3).Range) = 4 Then
        With tbl.Rows.First
            .Range.Font.Name = "Verdana"
            .Range.Font.Size = 7.5
            .Range.Font.Bold = True
            .Shading.BackgroundPatternColor = wdColorGray25
            .HeadingFormat = True
            .HeightRule = wdRowHeightAtLeast
            .Height = CentimetersToPoints(0.9)
        End With
    End If
 Next tbl

Open in new window

0
 
AndreasHermleAuthor Commented:
Hi Graham,

great, this did the trick. Thank you very much for your professional and swift support.

Regards, Andreas
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now