Consulting

Results 1 to 3 of 3

Thread: Select Next Rows

  1. #1
    VBAX Newbie
    Joined
    Jul 2017
    Posts
    2
    Location

    Select Next Rows

    How do you get VBA in Word to select the rows under the cursors' current position in a table? Ideally, select only the rows with text in the first column.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    You can select the next row with text in column 1 line this:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/11/2017
    Dim oRow As Row, oThisROw As Row
    Dim oTbl As Table
    Dim lngIndex As Long
      Set oTbl = Selection.Tables(1)
      Set oThisROw = Selection.Rows(1)
      For lngIndex = oThisROw.Index + 1 To oTbl.Rows.Count
        Set oRow = oTbl.Rows(lngIndex)
        If Len(oRow.Cells(1).Range.Text) > 2 Then
          oRow.Select
          Exit For
        End If
      Next
    lbl_Exit:
      Exit Sub
    End Sub
    Your not going to be able to select non-contiguous rows.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Jul 2017
    Posts
    2
    Location
    This code did not work. I got a "Can't execute code in break mode" at line Set oTbl = Selection.Tables(1). To bring things down to my level, perhaps just knowing how to select the next 2+ rows under the current position of the cursor would work. Thank you for your help thus far.

Posting Permissions

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