Error: Collection object not found

D

Dave Neve

Hello

I have a simple macro that chooses a line in a table at random to test
students on their vocab.

I have split a cell in the last column and now the macro produces the error
'Collection Object not found'.

I don't understand why one cell being split can cause this macro to fail.

After all, the table still exists and it selects the table while the number
of lines remain the same.

If someone indicate where the problem lies...

Thanks


Sub RandomPick()
'
' RandomPick Macro
' Macro créée le 18/06/2005 par Dave Neve
'
Dim i As Long
Dim j As Long
i = Selection.Tables(1).Rows.Count
Randomize
j = Int((i * Rnd) + 1)
Selection.Tables(1).Cell(j, Selection.Tables(1).Columns.Count).Select
Selection.HomeKey



End Sub
 
H

Helmut Weber

Hi Dave,

it seems, if you split just one cell,
the number of columns in the table increases by one.
But there is only one row which has this number of cells.
For all other rows you get the error message.

You have to get the number of cells in a row,
for your random picking.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top