Results 1 to 8 of 8

Thread: select a range in a table

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    9

    select a range in a table

    Does anyone know how to select a range of cells in vba?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: select a range in a table

    Here's one way:
    Code:
    Range("A3:B7").Select
    Note that ideally you should specify the sheet too, eg:
    Code:
    Sheet1.Range("A3:B7").Select

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    9

    Re: select a range in a table

    Quote Originally Posted by si_the_geek
    Here's one way:
    Code:
    Range("A3:B7").Select
    Note that ideally you should specify the sheet too, eg:
    Code:
    Sheet1.Range("A3:B7").Select
    A table in ms word

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: select a range in a table

    unless you want to display that selection to the user, is is best to work with the data in that cell, by address and avoid using selection
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: select a range in a table

    to answer the original question
    Documents(1).Tables(1).Rows(2).Select
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    9

    Re: select a range in a table

    Quote Originally Posted by westconn1
    to answer the original question
    Documents(1).Tables(1).Rows(2).Select
    wouldn't that just select the second row?

    I want to select a range of rows like row 2 through 5 for example

    I've searched alot on the web for an answer already so I won't be surprised if this is impossible to do in ms word tables.

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: select a range in a table

    Many ways to do that:
    Code:
       With ActiveDocument
          .Range(Start:=.Tables(1).Rows(2).Range.Start, _
                 End:=.Tables(1).Rows(5).Range.End).Select
       End With
    or
    Code:
       ActiveDocument.Tables(1).Rows(2).Range.Select
       Selection.MoveEnd Unit:=wdRow, Count:=3
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    9

    Re: select a range in a table

    Quote Originally Posted by anhn
    Many ways to do that:
    Code:
       With ActiveDocument
          .Range(Start:=.Tables(1).Rows(2).Range.Start, _
                 End:=.Tables(1).Rows(5).Range.End).Select
       End With
    or
    Code:
       ActiveDocument.Tables(1).Rows(2).Range.Select
       Selection.MoveEnd Unit:=wdRow, Count:=3
    Thank you for the help. I will try that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width