PDA

View Full Version : Select Next Rows



curtiscx
07-11-2017, 05:47 PM
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.

gmaxey
07-11-2017, 06:12 PM
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.

curtiscx
07-12-2017, 07:10 AM
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.