Forum Discussion
a_bonsey
May 16, 2022Brass Contributor
vba table valid row count
Hi, I'm supplied Word documents that contain a table that has differing valid rows therefore I need a variable to count the valid rows. In Excel this would be something like: Sub Test()
Wi...
a_bonsey Is a line of the code highlighted when it fails?
This is the result of running the code here
a_bonsey
May 17, 2022Brass Contributor
- May 17, 2022
a_bonsey Can you upload a copy of the document
- a_bonseyMay 17, 2022Brass Contributor
Sure. Here you go
- May 17, 2022
a_bonsey That document contains a Word table, not an Excel worksheet.
The following macro will tell you how many rows contain data:
With ActiveDocument.Tables(1) For i = 1 To .Rows.Count If Len(.Cell(i, 1).Range) < 3 Then Exit For End If Next i End With MsgBox "The table contains data in " & i - 1 & " rows, including the header row."