Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

A quick way to select several cells in a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay - 02 Sep 2005 14:02 GMT
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
Greg - 02 Sep 2005 16:53 GMT
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
Helmut Weber - 07 Sep 2005 14:37 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg - 07 Sep 2005 17:01 GMT
Helmut,

Yes, interesting.  Thanks.
Jay - 08 Sep 2005 11:36 GMT
Thanks Greg + Helmut.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.