How do I reference cells in a Word table?

W

William Bub

In a large Word table, is it possible (staying in Word and not using Excel)
to, for example, have column A contain a number, and coulmn B contain that
number plus 4, for a large number of rows? I would like to do this without
having to enter a different formula in each of the column B cells. Is there
any way to use relative cell addressing? A macro to enter the formulas,
perhaps?
 
G

Greg Maxey

William,

A VBA maestro would probably call this crude, but you might try the
following:

Sub ScratchMacro()
Dim i As Long
Dim aValue As Range
Dim bValue As Range
Dim oTbl As Table
Set oTbl = Selection.Tables(1)
For i = 1 To oTbl.Rows.Count
Set aValue = oTbl.Cell(i, 1).Range
If IsNumeric(aValue) Then
With aValue
.MoveEnd Unit:=wdCharacter, Count:=-1
End With
Set bValue = oTbl.Cell(i, 2).Range
bValue = aValue + 4
End If
Next

End Sub
 

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