A quick way to select several cells in a table

J

Jay

Hi,

I know that I can select one cell in a column by using something
like...
activedocument.Tables(1).Columns(2).Cells(2).Select
....but is there a way to select several cells in a column, something
like...
activedocument.Tables(1).Columns(2).Cells(2:5).Select
....while is invalid syntax ofcourse, but hopefully it gets my point
across.

Thanks in anticipation...

Jay
 
G

Greg

Jay,

Here is one way:

Sub ScratchMacro()
Dim oRng As Range

With ActiveDocument.Tables(1)
Set oRng = .Cell(2, 1).Range
oRng.End = .Cell(5, 1).Range.End
End With
oRng.Select
End Sub
 
H

Helmut Weber

Hi Greg, hi Jay,

beware of possible complications,
with ranges in tables ;-)

For a table with 5 columns and 10 rows:

Sub ScratchMacro2()
Dim oRng As Range
With ActiveDocument.Tables(1)
Set oRng = .Cell(2, 1).Range
oRng.End = .Cell(5, 1).Range.End
End With
oRng.Select
MsgBox Selection.Cells.Count ' 4
MsgBox Selection.Range.Cells.Count ' 16
MsgBox oRng.Cells.Count ' 16
End Sub

--
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