Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 07-22-2017, 12:53 AM
gmayor's Avatar
gmayor gmayor is offline Find and Replace rows in a table based on bold text. Windows 10 Find and Replace rows in a table based on bold text. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Without the tables, it is impossible to test against what you have, but the following should be close
Code:
Option Explicit

Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 22 Jul 2017
Const myKeyTerms As String = _
      "Aerospace, Space & Defence"
Dim oDoc As Document
Dim oTarget As Document
Dim oTable As Table
Dim oRng As Range
Dim oNew As Range
Dim oCell As Cell

    Set oDoc = ActiveDocument
    Set oTarget = Documents.Add
    oTarget.Range.Text = myKeyTerms & vbCr
    oTarget.Paragraphs(1).Range.Font.Bold = True
    If oDoc.Tables.Count = 0 Then
        MsgBox "No tables in this document?"
        GoTo lbl_Exit
    End If
    For Each oTable In oDoc.Tables
        Set oRng = oTable.Range
        With oRng.Find
            Do While .Execute(FindText:=myKeyTerms)
                If oRng.InRange(oTable.Range) Then
                    If oRng.Font.Bold = True Then
                        oRng.Start = oRng.Rows(1).Range.Next.Rows(1).Range.Start
                        oRng.End = oTable.Range.End
                        For Each oCell In oRng.Cells
                            If oCell.Range.Font.Bold = True Then
                                oRng.End = oCell.Range.Start
                                Exit For
                            End If
                        Next oCell
                        Exit Do
                    End If
                End If
                oRng.Collapse 0
            Loop
        End With
        Set oNew = oTarget.Range
        oNew.Collapse 0
        oNew.FormattedText = oRng.FormattedText
    Next oTable
lbl_Exit:
    Set oDoc = Nothing
    Set oTarget = Nothing
    Set oRng = Nothing
    Set oNew = Nothing
    Set oTable = Nothing
    Set oCell = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace rows in a table based on bold text. Macro to find and replace headings in bold and underline redzan Word VBA 4 02-13-2016 12:24 PM
Find and Replace rows in a table based on bold text. Find, select, and replace part of text with bold paik1002 Word VBA 4 12-07-2015 11:24 PM
Find and Replace rows in a table based on bold text. 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
Find and Replace rows in a table based on bold text. find and replace in bold redzan Word VBA 1 07-27-2014 03:35 PM
Find and Replace rows in a table based on bold text. Word VBA Macro to Find and Replace based on the Alt Text of an Image bennymc Word VBA 1 01-27-2014 04:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:14 PM.


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