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
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."
- a_bonseyMay 18, 2022Brass Contributor
Hi,
I tried tweaking the vba slightly to see what a debug/msgbox would should for the cell(i,1). In the debug (and Msgbox) I get a 'rectangular box' appearing (see attached image).
Are you able to tell me what causes this to appear?