Error Handling in MS Word, Merged rows count issue

Hi Experts,

I have a Word Macro that I wrote that is supposed to count the number of rows in Column 1 of this table, as some are merged the usual table.rows.count doesn't work.
Any suggestions as to why I get a Debug Error when "only stop on unhandled errors" is selected at the line marked *, when I get to row 4, when in column 1 there are actually only 3 rows, due to merging.  I know why the error occurs, I don't know how to handle it so it doesn't stop.

Code:
Function fMergedRows() As String
On Error GoTo Err_handler
   
Dim tbl As Table
Dim i As Integer
Dim strComma As String
Dim strMergedRows As String

    Set tbl = ActiveDocument.Tables(1)
   
    strComma = ""
   
    For i = 1 To tbl.Rows.Count
        Debug.Print tbl.Cell(i, 1).Creator
        fMergedRows = fMergedRows & strComma & i
        strComma = ","
        Debug.Print fMergedRows
ErrBack:
    Next i
   
Exit Function
Err_handler:
    GoTo ErrBack

End Function
LVL 1
Craig LambieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
You can find the number of columns in Row 1 from the cell count.
Row1Cols = tbl.Columns(1).Cells.Count.

The reason that the error is displayed is that you enter the error handling procedure after the first occurrence of an error and never come out of it, so the second error will cause a break.
Use Resume to end error processing:

Function fMergedRows() As String
On Error GoTo Err_handler
   
Dim tbl As Table
Dim i As Integer
Dim strComma As String
Dim strMergedRows As String

    Set tbl = ActiveDocument.Tables(1)
   
    strComma = ""
   
    For i = 1 To tbl.Rows.Count
        Debug.Print tbl.Cell(i, 1).Creator
        fMergedRows = fMergedRows & strComma & i
        strComma = ","
        Debug.Print fMergedRows
ErrBack:
    Next i
   
Exit Function
Err_handler:
    Resume ErrBack

End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.