Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-02-2015, 08:22 PM
macropod's Avatar
macropod macropod is offline VBA Word - Find Specific Table - Prepend & Append Data to Each Cell Windows 7 64bit VBA Word - Find Specific Table - Prepend & Append Data to Each Cell Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try something based on:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim oTbl As Table, i As Long, r As Long, Rng As Range
For Each oTbl In ActiveDocument.Tables
  With oTbl
    If InStr(.Cell(1, 2).Range.Text, "#CPT") > 0 Then
      Set Rng = .Cell(2, 1).Range
      With Rng
        .End = .End - 1
        .InsertBefore "(Year) "
        i = InStr(.Text, " ")
        With .Duplicate
          .End = .Start + i
          .Font.ColorIndex = wdBlue
        End With
        .InsertAfter " (Building)"
        i = InStrRev(.Text, " ")
        With .Duplicate
          .Start = .Start + i
          .Font.ColorIndex = wdBlue
        End With
      End With
      Set Rng = .Cell(2, 2).Range
      With Rng
        .End = .End - 1
        .InsertBefore "(QID) "
        i = InStr(.Text, " ")
        With .Duplicate
          .End = .Start + i
          .Font.ColorIndex = wdBlue
        End With
        .InsertAfter " (Total)"
        i = InStrRev(.Text, " ")
        With .Duplicate
          .Start = .Start + i
          .Font.ColorIndex = wdBlue
        End With
      End With
    For r = 3 To .Rows.Count
      Set Rng = .Cell(r, 1).Range
      With Rng
        .End = .End - 1
        .InsertBefore "(student) "
        i = InStr(.Text, " ")
        With .Duplicate
          .End = .Start + i
          .Font.ColorIndex = wdBlue
        End With
        .InsertAfter " (Course)"
        i = InStrRev(.Text, " ")
        With .Duplicate
          .Start = .Start + i
          .Font.ColorIndex = wdBlue
        End With
      End With
      Set Rng = .Cell(r, 2).Range
      With Rng
        .End = .End - 1
        .InsertBefore "(previous) "
        i = InStr(.Text, " ")
        With .Duplicate
          .End = .Start + i
          .Font.ColorIndex = wdBlue
        End With
        .InsertAfter " (Pass)"
        i = InStrRev(.Text, " ")
        With .Duplicate
          .Start = .Start + i
          .Font.ColorIndex = wdBlue
        End With
      End With
    Next
    End If
  End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Word - Find Specific Table - Prepend & Append Data to Each Cell VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color jc491 Word VBA 8 09-30-2015 06:10 AM
Word 2013 - linking cell data within a table jhamblin Word Tables 1 03-15-2015 01:32 AM
VBA Word - Find Specific Table - Prepend & Append Data to Each Cell How to append specific *.tif image with another tif file through Word VBA aarun2 Word VBA 1 04-08-2014 03:20 PM
Append text to a sentence containing specific word dgp Word VBA 3 02-28-2014 10:38 PM
Word table - how do I append % symbol to each value in columns 3 & 4 of a table Dawsie Word 4 03-06-2013 12:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft