• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 718
  • Last Modified:

Select continuous cells in a Word table column

With VBA in Word 2010, if I have

     Dim col as Column
     set col = Activedocument.tables(1).columns(3)

is there not a short, one-line command to select cells x to y in that column?
I'd even take a two or three line command.
Thanks!
   j.r.a.
0
JohnRobinAllen
Asked:
JohnRobinAllen
  • 2
  • 2
2 Solutions
 
Chris BottomleyCommented:
Short ... not especially unless you split it down into ranges and then recombine but the net effect either via a with or ranges is as follows~:

activedocument.range(activedocument.tables(1).columns(1).cells(2).Range.Start, activedocument.tables(1).columns(1).cells(4).Range.end).Select

Chris
0
 
Chris BottomleyCommented:
i.e. via ranges:

Sub aRange()
Dim rngFirst As Range
Dim rngLast As Range

    Set rngFirst = ActiveDocument.Tables(1).Columns(1).Cells(2).Range
    Set rngLast = ActiveDocument.Tables(1).Columns(1).Cells(4).Range
    ActiveDocument.Range(rngFirst.Start, rngLast.End).Select
    
End Sub

Open in new window


or via 'with'

Sub bRange()

    With ActiveDocument.Tables(1).Columns(1)
        ActiveDocument.Range(.Cells(2).Range.Start, .Cells(4).Range.End).Select
    End With
    
End Sub

Open in new window


Chris
0
 
GrahamSkanCommented:
Be a bit careful if you want to use the selection programatically.

Selection.Text returns the contents of the first cell only

Select.Range.Text includes the contents of cells from other columns that are between the first and last cell
0
 
JohnRobinAllenAuthor Commented:
Chris solved the problem and gets full credit. Graham's comment is important and deserves extra points for it. Thanks to both.<br />     It is a sunny day today in Priddis, Alberta, both outside (with the weather) and inside (thanks to the solution provided above). <br />     
--j.r.a.
0
 
GrahamSkanCommented:
It's sunny where I am the UK today as well. Chris is about 100 miles north, but I guess that it's about the same.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now