View Single Post
 
Old 07-05-2018, 06:47 AM
slaycock slaycock is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Will you be selecting the row in the table before you run the macro or will you just expect the macro to process Table(8).

Providing more information goes both ways you know.

Code:
Public Function find_last_empty_cell_in_range(this_range As Word.Range) As Long
' Searches through the cells in the table and returns the index of the first empty cell.
' The input parameter is a word range so the function is generic for a table
' or a selection within a table
'
' This function will work with non uniform tables
' Scanning a table using the range.cell(x,y) method will fail with non-uniforma tables
'
' We test if the length of the text in the cell is 2 or less characters to find an empty cell.
' This is because Cells contain hidden characters which mark the end of the cell
' and end of the text (I think)

Dim my_cell                                         As Word.Cell
Dim my_index                                        As Long

    For my_index = 1 To this_range.Cells.Count
        With this_range
            If Len(.Cells(my_index).Range.Text) <= 2 Then
                find_last_empty_cell_in_range = my_index
                Exit Function
            End If
        End With
    Next
End Function

Sub find_cell()

Dim my_range                            As Word.Range

    Set my_range = ActiveDocument.Tables(8).Range

    Debug.Print find_last_empty_cell_in_range(my_range)
 
End Sub
Reply With Quote