B
Benjamino5
I'd read online that For...Each loops were faster in general than using a
counter. However, in the following code, AltMergeTable is running much faster
than MergeTable.
Did I get bad info about For...Each being faster? Or is it true in other
circumstances? I know I could (and will) do a lot of testing, but I'm curious
to know if there are any rules of thumb you can suggest for deciding whether
to use For...Each vs. using a counter.
My macro is running very slowly, and I'm trying to tackle it piece by piece,
so if you have any other ideas about how to speed up AltMergeTable even more,
please let me know!
Thanks,
Ben
______________________________________
Sub MergeTable(doc As Document, oTable As Table)
Dim oRow As Row
For Each oRow In oTable.Rows
oRow.Cells.Merge
If InStr(oRow.Range, "Ans:") = 0 Then
Call ParaMarkToTab(oRow.Cells(1))
End If
Next oRow
End Sub
Sub AltMergeTable(doc As Document, oTable As Table)
Dim i As Integer
For i = 1 To oTable.Rows.Count
oTable.Rows(i).Cells.Merge
If InStr(oTable.Rows(i).Range, "Ans:") = 0 Then
Call ParaMarkToTab(oTable.Rows(i).Cells(1))
End If
i = i + 1
Next i
End Sub
counter. However, in the following code, AltMergeTable is running much faster
than MergeTable.
Did I get bad info about For...Each being faster? Or is it true in other
circumstances? I know I could (and will) do a lot of testing, but I'm curious
to know if there are any rules of thumb you can suggest for deciding whether
to use For...Each vs. using a counter.
My macro is running very slowly, and I'm trying to tackle it piece by piece,
so if you have any other ideas about how to speed up AltMergeTable even more,
please let me know!
Thanks,
Ben
______________________________________
Sub MergeTable(doc As Document, oTable As Table)
Dim oRow As Row
For Each oRow In oTable.Rows
oRow.Cells.Merge
If InStr(oRow.Range, "Ans:") = 0 Then
Call ParaMarkToTab(oRow.Cells(1))
End If
Next oRow
End Sub
Sub AltMergeTable(doc As Document, oTable As Table)
Dim i As Integer
For i = 1 To oTable.Rows.Count
oTable.Rows(i).Cells.Merge
If InStr(oTable.Rows(i).Range, "Ans:") = 0 Then
Call ParaMarkToTab(oTable.Rows(i).Cells(1))
End If
i = i + 1
Next i
End Sub