Question : Problem setting Table(3).columns.first as range

Hi experts
I cannot work out how to select Tables(3).columns.first.range as range.

See my code below. Basically what I effectively want is:

Instead of this:
                Dim myRange As Range
                Set myRange = ActiveDocument.Tables(3).Range

Make it this:
                Dim myRange As Range
                Set myRange = ActiveDocument.Tables(3).Columns(1).Range

But it won't let me do that. I want the myRange.find to be looking in the first column of table 3 only.

Help, Help, HELP!!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
Private Sub DocControlAdd()


    Dim texta, textb, textc, textd, texte, textf As String
    texta = ActiveDocument.CustomDocumentProperties.Item("xRevisionNo")
    textb = ActiveDocument.CustomDocumentProperties.Item("xRevisionDate")
    textc = ActiveDocument.CustomDocumentProperties.Item("xDetails")
    textd = ActiveDocument.CustomDocumentProperties.Item("xPreparedby")
    texte = ActiveDocument.CustomDocumentProperties.Item("xReviewedby")
    textf = ActiveDocument.CustomDocumentProperties.Item("xApprovedby")



    ActiveDocument.Tables(3).Range.Select

        If ActiveDocument.CustomDocumentProperties.Item("xNew") = "Y" Then
            Selection.Tables(1).Rows(1).Cells(1).Select
            Selection.Tables(1).Rows.Add
            Selection.MoveDown Unit:=wdLine, Count:=1
        
        ElseIf NewVersion = True Then
        
            Selection.Tables(1).Rows.Last.Select
            Selection.Tables(1).Rows.Add
            Selection.MoveDown Unit:=wdLine, Count:=1
            
        ElseIf NewVersion = False Then
                         
                Dim myRange As Range
                Set myRange = ActiveDocument.Tables(3).Range
                
                With myRange.Find
                .ClearFormatting
                .MatchWholeWord = True
                .MatchCase = True
                .Execute FindText:=texta
                End With
                         
                If myRange.Find.Found = True Then
                    myRange.Cells(1).Select
                End If
           
            
         End If
         
          Selection.TypeText texta
            
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText textb
            
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText textc
            
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText textd
            
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText texte
            
            Selection.MoveRight Unit:=wdCell
            Selection.TypeText textf
    ActiveDocument.CustomDocumentProperties.Item("xRevisionNoOld").Value = ActiveDocument.CustomDocumentProperties.Item("xRevisionNo").Value

End Sub

Answer : Problem setting Table(3).columns.first as range

In general, I advise using a Range object instead of the Selection object where possible. Also it is easier to see what you are are trying to do (and hence easier to maintain) if you specify where you want to be in terms of the objects, as opposed to MoveDown and MoveRight, etc.

However you can Select and search a single column.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
Private Sub DocControlAdd()
   'Dim texta, textb, textc, textd, texte, textf As String 'this Dims all except the last variable as a variant

    Dim texta As String, textb As String, textc As String, textd As String, texte As String, textf As String
     Dim tbl As Table
    Dim rw As Row
    Dim cl As Cell
    Dim c As Integer
    Dim iStartCol As Integer
    
    texta = ActiveDocument.CustomDocumentProperties.Item("xRevisionNo")
    textb = ActiveDocument.CustomDocumentProperties.Item("xRevisionDate")
    textc = ActiveDocument.CustomDocumentProperties.Item("xDetails")
    textd = ActiveDocument.CustomDocumentProperties.Item("xPreparedby")
    texte = ActiveDocument.CustomDocumentProperties.Item("xReviewedby")
    textf = ActiveDocument.CustomDocumentProperties.Item("xApprovedby")
    iStartCol = 1
   Set tbl = ActiveDocument.Tables(1)

        If ActiveDocument.CustomDocumentProperties.Item("xNew") = "Y" Then
            Set rw = tbl.Rows.Add
        ElseIf NewVersion = True Then
            Set rw = tbl.Rows.Add
        ElseIf NewVersion = False Then
                tbl.Columns(iStartCol).Select
                With Selection.Find
                    .ClearFormatting
                    .MatchWholeWord = True
                    .MatchCase = True
                    If .Execute(FindText:=texta) Then
                        Set cl = Selection.Cells(1)
                        Set rw = tbl.Rows(cl.RowIndex)
                     End If
                End With
         End If
         c = iStartCol
         rw.Cells(c).Range.Text = texta
         c = c + 1
         rw.Cells(c).Range.Text = textb
         c = c + 1
         rw.Cells(c).Range.Text = textc
         c = c + 1
         rw.Cells(c).Range.Text = textd
         c = c + 1
         rw.Cells(c).Range.Text = texte
         c = c + 1
         rw.Cells(c).Range.Text = textf
    ActiveDocument.CustomDocumentProperties.Item("xRevisionNoOld").Value = ActiveDocument.CustomDocumentProperties.Item("xRevisionNo").Value

End Sub
Random Solutions  
 
programming4us programming4us