View Single Post
 
Old 08-17-2022, 04:32 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,602
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim oCell As Cell
  Set oTbl = Selection.Tables(1)
  For Each oCell In oTbl.Range.Cells
    If oCell.ColumnIndex = 1 Then
      If Len(oCell.Range.Text) > 2 Then
        oCell.Range.InsertBefore "Gen "
      End If
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub
Sub ScratchMacro2()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim oCol As Column
Dim oCell As Cell
  Set oTbl = Selection.Tables(1)
  If oTbl.Uniform Then
    Set oCol = oTbl.Columns(1)
    For Each oCell In oCol.Cells
      If oCell.ColumnIndex = 1 Then
        If Len(oCell.Range.Text) > 2 Then
          oCell.Range.InsertBefore "Gen "
        End If
      End If
    Next
  End If
lbl_Exit:
  Exit Sub
End Sub

If the table is uniform, the second macro will be faster.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote