PDA

View Full Version : [SOLVED:] Error - cannot access individual rows in this collection



DavG63
01-26-2016, 03:45 AM
Hi,

I have the following code in place, which is supposed to examine which rows in a table have no value and thereafter delete that row. In my document there are two identical tables, which appear at paragraphs 2 and 4.


Application.ScreenUpdating = FalseDim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean
With ActiveDocument
For Each Tbl In .Tables
n = Tbl.Rows.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Rows(i).Cells
If Len(cel.Range.Text) > 2 Then
fEmpty = False
Exit For
End If
Next cel


If fEmpty = True Then Tbl.Rows(i).Delete
Next i
Next Tbl
End With


Set cel = Nothing: Set Tbl = Nothing
Application.ScreenUpdating = True

For some reason each time this runs, I get an error "cannot access individual rows in this collection" once it reaches

For Each cel In Tbl.Rows(i).Cells

If I debug and remove Tbl.Rows and replace it with Tbl.Columns, I get an error, but then if I switch it back to Tbl.Rows it runs as it should.

Does anyone know why this would possibly be the case? It seems to defy logic as far as I'm concerned.

Thanks

Dav

DavG63
01-26-2016, 07:27 AM
I now know why this didn't work. I had forgotten that earlier in the same document there were other 'boxes' for lack of a better word where information appeared. These were actually merged table cells and were being picked up by the macro.

I've now specified a section for the macro to limit itself to, and hopefully that should solve the problem.

Paul_Hossler
01-26-2016, 07:54 AM
If you go to [Thread Tools] at the top, you can mark the issue [Solved]


15287