I have a pretty fast machine (everything else I do goes at 'lightning
speed'). Yet it takes almost 20 seconds for my computer to read the 300
row/2 column table. Am I doing something inefficient with this formula?

-------snip-------------

Set otable = Selection.Tables(1)
NumRows=otable.Rows.count ' this ranges from 300 to 350
redim Name1(NumRows)
redim Name2(NumRows)
With otable
For nRow = 1 To NumRows
Name1(nRow) = .Cell(nRow, 1)
Name2(nRow) = .Cell(nRow, 2)
Next
End With

------snip--------------

What improvements are possible? Are reads from tables just inherently slow?
Thanks.


-- Ed

RE: Tables--Reading them Quickly by nospam>

nospam>
Wed Apr 06 07:09:06 CDT 2005

I'm no expert but I think you'll find this is a much faster way to loop
through all cells in a table:

Set oCell = oTable.Range.Cells(1).Range
Do
oCell.Style = '... or whatever you want to do here
Set oCell = oCell.Next(wdCell)
Loop

Hope this helps.
S

"asrisl" wrote:

> I have a pretty fast machine (everything else I do goes at 'lightning
> speed'). Yet it takes almost 20 seconds for my computer to read the 300
> row/2 column table. Am I doing something inefficient with this formula?
>
> -------snip-------------
>
> Set otable = Selection.Tables(1)
> NumRows=otable.Rows.count ' this ranges from 300 to 350
> redim Name1(NumRows)
> redim Name2(NumRows)
> With otable
> For nRow = 1 To NumRows
> Name1(nRow) = .Cell(nRow, 1)
> Name2(nRow) = .Cell(nRow, 2)
> Next
> End With
>
> ------snip--------------
>
> What improvements are possible? Are reads from tables just inherently slow?
> Thanks.
>
>
> -- Ed
>
>
>

Re: Tables--Reading them Quickly by Dave

Dave
Wed Apr 06 07:59:59 CDT 2005

Hi Ed,

You should have a look at the artilce "Maximising the performance of Word
tables" at http://word.mvps.org/faqs/tblsfldsfms/FastTables.htm. The article
addresses your issue:

When cycling through table cells, never refer to a table cell by its
coordinates; as that is horrendously slow, because it forces Word to
calculate from scratch, for every single cell, where in the document the
cell in question actually is.



You're doing just that with .Cell (nRow,1) and .Cell(nRow, 2). I think
that's why it's taking so long for your routine to run.

HTH,

Dave



"asrisl" <asrisl@cox.net> wrote in message news:95Q4e.30$ih3.2@lakeread06...
> I have a pretty fast machine (everything else I do goes at 'lightning
> speed'). Yet it takes almost 20 seconds for my computer to read the 300
> row/2 column table. Am I doing something inefficient with this formula?
>
> -------snip-------------
>
> Set otable = Selection.Tables(1)
> NumRows=otable.Rows.count ' this ranges from 300 to 350
> redim Name1(NumRows)
> redim Name2(NumRows)
> With otable
> For nRow = 1 To NumRows
> Name1(nRow) = .Cell(nRow, 1)
> Name2(nRow) = .Cell(nRow, 2)
> Next
> End With
>
> ------snip--------------
>
> What improvements are possible? Are reads from tables just inherently
slow?
> Thanks.
>
>
> -- Ed
>
>



Re: Tables--Reading them Quickly by Helmut

Helmut
Wed Apr 06 08:05:04 CDT 2005

Hi Ed,

have a look at this one:

Sub test68869()
Dim c As Cell
Dim l As Long
l = Selection.Tables(1).Rows.Count
ReDim Name1(l) ' As Variant
ReDim Name2(l) ' As Variant
x = Timer
With Selection.Tables(1)
l = 0
.Columns(1).Select
For Each c In Selection.Cells
l = l + 1
Name1(l) = c.Range.Text
Next
.Columns(2).Select
l = 0
For Each c In Selection.Cells
l = l + 1
Name1(l) = c.Range.Text
Next
End With
MsgBox Timer - x
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000

Re: Tables--Reading them Quickly by asrisl

asrisl
Thu Apr 07 06:04:58 CDT 2005

Perfect!! Thanks.
-- Ed




Re: Tables--Reading them Quickly by Klaus

Klaus
Fri Apr 08 19:07:31 CDT 2005

Another one:

Dim oTable As Table
Dim varTable As Variant
Dim Start
Dim NumRows As Long, nRow As Long
Start =3D Timer
Set oTable =3D Selection.Tables(1)
NumRows =3D oTable.Rows.Count ' this ranges from 300 to 350
ReDim Name1(NumRows)
ReDim Name2(NumRows)
varTable =3D oTable.Range.Text
varTable =3D Split(varTable, Chr(13) & Chr(7))
For nRow =3D 0 To NumRows Step 3
Name1(nRow) =3D varTable(nRow)
Name2(nRow) =3D varTable(nRow + 1)
Next
MsgBox Timer - Start

Regards,
Klaus



"asrisl" <asrisl@cox.net> schrieb im Newsbeitrag =
news:95Q4e.30$ih3.2@lakeread06...
> I have a pretty fast machine (everything else I do goes at 'lightning
> speed'). Yet it takes almost 20 seconds for my computer to read the =
300
> row/2 column table. Am I doing something inefficient with this =
formula?
>=20
> -------snip-------------
>=20
> Set otable =3D Selection.Tables(1)
> NumRows=3Dotable.Rows.count ' this ranges from 300 to 350
> redim Name1(NumRows)
> redim Name2(NumRows)
> With otable
> For nRow =3D 1 To NumRows
> Name1(nRow) =3D .Cell(nRow, 1)
> Name2(nRow) =3D .Cell(nRow, 2)
> Next
> End With
>=20
> ------snip--------------
>=20
> What improvements are possible? Are reads from tables just inherently =
slow?
> Thanks.
>=20
>=20
> -- Ed
>=20
>