G
Greg
I scratched together the following macro earlier today to help and
Tables Group OP with a question for population a freight shipping
scale. The OP scale has four columns 1)weight in 100 lbs increments,
2) a flat fee, 3) a rate, and 4) total. He needed a scale from 100 to
80,000 pounds. He has the 801 row table with the headings. Here is
the code:
Sub FillinRateScale()
Dim oTbl As Table
Dim i As Long
Dim x As Double
Dim y As Double
Set oTbl = ActiveDocument.Tables(1)
For i = 2 To oTbl.Rows.Count
With oTbl
.Cell(i, 1).Range.Text = (100 * i) - 100
.Cell(i, 2).Range.Text = "$160.00"
.Cell(i, 3).Range.Text = Format((3 * i) - 3, "$#,###.00")
x = Left(.Cell(i, 2).Range, Len(.Cell(i, 2).Range) - 2)
y = Left(.Cell(i, 3).Range, Len(.Cell(i, 3).Range) - 2)
.Cell(i, 4).Range = Format(x + y, "$#,###.00")
End With
Next
End Sub
On my machine here it took 103 seconds to populate the table. I
thought I would get a noticeable reduction in time if I changed:
For i = 2 to oTbl.Rows.Count
to
For i = 2 to 801 'Since I know the number of rows and the macro would
not have to recount each time. While I didn't measure precisely, I
didn't see any reduction in time.
Would welcome comment on ways to make this sort of thing run faster.
Thanks.
Tables Group OP with a question for population a freight shipping
scale. The OP scale has four columns 1)weight in 100 lbs increments,
2) a flat fee, 3) a rate, and 4) total. He needed a scale from 100 to
80,000 pounds. He has the 801 row table with the headings. Here is
the code:
Sub FillinRateScale()
Dim oTbl As Table
Dim i As Long
Dim x As Double
Dim y As Double
Set oTbl = ActiveDocument.Tables(1)
For i = 2 To oTbl.Rows.Count
With oTbl
.Cell(i, 1).Range.Text = (100 * i) - 100
.Cell(i, 2).Range.Text = "$160.00"
.Cell(i, 3).Range.Text = Format((3 * i) - 3, "$#,###.00")
x = Left(.Cell(i, 2).Range, Len(.Cell(i, 2).Range) - 2)
y = Left(.Cell(i, 3).Range, Len(.Cell(i, 3).Range) - 2)
.Cell(i, 4).Range = Format(x + y, "$#,###.00")
End With
Next
End Sub
On my machine here it took 103 seconds to populate the table. I
thought I would get a noticeable reduction in time if I changed:
For i = 2 to oTbl.Rows.Count
to
For i = 2 to 801 'Since I know the number of rows and the macro would
not have to recount each time. While I didn't measure precisely, I
didn't see any reduction in time.
Would welcome comment on ways to make this sort of thing run faster.
Thanks.