Detect if a cell is empty


Method 1

Uses the basis that an empty cell consists of a paragraph mark followed by Chr(7).

Public Sub CheckTableCells 
Dim objCell As Cell
Dim objRow As Row

   For Each objRow In Selection.Tables(1).Rows
      For Each objCell In objRow.Cells
         If objCell.Range.Text = Chr(13) & Chr(7) Then
            Call MsgBox("objCell.RowIndex & " " & objCell.ColumnIndex & " is empty"
         End If
      Next objCell
   Next objRow
End Sub

Method 2

Uses a Range variable

Public Sub CheckTableCells 
Dim objCell As Cell
Dim objRow As Row
Dim objRange As Range

   For Each objRow In Selection.Tables(1).Rows
      For Each objCell In objRow.Cells
         Set objRange = objCell.Range
'move to the end so the end of cell marker and paragraph marker are not included (only 1 character)
         objRange.End = objRange.End - 1
         If Len(objRange.Text) = 0 Then
            Call MsgBox("objCell.RowIndex & " " & objCell.ColumnIndex & " is empty"
         End If
      Next objCell
   Next objRow
End Sub



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext