PDA

View Full Version : Looping through column



bigal.nz
11-17-2014, 01:21 AM
Hi All,

I want to loop through every the first cell in every row of a table.

The table has one cell that spans across the top of all columns (merged) but from row2 onwards has 4 colums and dpending on the size of the list can have an infinite number of rows.

How would I loop through the first column in each row, but not row1.

I had this :




Private Sub CommandButton2_Click()

Set ChargesTable = ActiveDocument.Tables(1)
For Each oRow In ChargesTable.Rows
Set oCell = oRow.Cells(1)
MsgBox oCell.Range.Text
Next

End Sub



But that doesnt start at row 2.

Cheers

-Al

macropod
11-17-2014, 05:26 AM
Try:

Private Sub CommandButton2_Click()
Dim i As Long, Rng As Range
With ActiveDocument.Tables(1)
If .Rows.Count = 1 Then Exit Sub
For i = 2 To .Rows.Count
Set Rng = .Cell(i, 1).Range
With Rng
.End = .End - 1
MsgBox .Text
End With
Next
End With
End Sub