Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 03-08-2023, 09:40 PM
gmayor's Avatar
gmayor gmayor is offline Find a text that's equal to "HELLO" in a table cell and copy the left side content. Windows 10 Find a text that's equal to "HELLO" in a table cell and copy the left side content. Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
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

To add the hyperlinks you would need something to link to. The following bookmarks the found items and links to those.

Code:
Sub Macro1()
Dim oTable As Table
Dim oCell As Cell
Dim oRng As Range, oHeader As Range
Dim oColl As Collection
Dim i As Long, j As Long
    j = 0
    Set oColl = New Collection
    For Each oTable In ActiveDocument.Tables
        For Each oCell In oTable.Range.Cells
            If InStr(1, oCell.Range.Text, "HELLO") > 0 Then
                If oCell.Range.Font.ColorIndex = wdBlue Then
                    j = j + 1
                    Set oRng = oCell.Previous.Range
                    oRng.End = oRng.End - 1
                    oRng.Bookmarks.Add "BM" & j
                    Set oHeader = oCell.Range.Sections(1).Headers(wdHeaderFooterPrimary).Range
                    oHeader.End = oHeader.End - 1

                    Select Case True
                        Case InStr(1, oRng.Text, "APPLE") > 0
                            oColl.Add "I LIKE APPLES|" _
                                      & oRng.Text & "|" _
                                      & oHeader.Text & "|" _
                                      & oRng.Information(wdActiveEndPageNumber)
                        Case InStr(1, oRng.Text, "CAR RESALES") > 0
                            oColl.Add "I DON'T LIKE BANANA|" _
                                      & oRng.Text & "|" _
                                      & oHeader.Text & "|" & _
                                      oRng.Information(wdActiveEndPageNumber)
                    End Select
                End If
            End If
        Next oCell
    Next oTable
    Set oRng = ActiveDocument.Range
    oRng.Collapse 0
    oRng.InsertParagraphBefore
    Set oTable = ActiveDocument.Tables.Add(oRng, oColl.Count + 1, 4)
    With oTable
        .Columns(1).Width = CentimetersToPoints(4)
        .Columns(2).Width = CentimetersToPoints(5)
        .Columns(3).Width = CentimetersToPoints(4.5)
        .Columns(4).Width = CentimetersToPoints(1.5)
        .Rows(1).Range.Font.Bold = True
        .Cell(1, 1).Range.Text = "Certification"
        .Cell(1, 2).Range.Text = "Title"
        .Cell(1, 3).Range.Text = "Section"
        .Cell(1, 4).Range.Text = "Page"
        .Rows(1).HeadingFormat = True
        For i = 1 To oColl.Count
            .Rows(i + 1).Cells(1).Range.Text = Split(oColl(i), "|")(0)
            .Rows(i + 1).Cells(2).Range.Text = Split(oColl(i), "|")(1)
            .Rows(i + 1).Cells(3).Range.Text = Split(oColl(i), "|")(2)
            .Rows(i + 1).Cells(4).Range.Text = Split(oColl(i), "|")(3)
            ActiveDocument.Hyperlinks.Add _
                    Anchor:=.Rows(i + 1).Cells(4).Range, _
                    Address:="", _
                    SubAddress:="BM" & Split(oColl(i), "|")(3), _
                    ScreenTip:="", _
                    TextToDisplay:=Split(oColl(i), "|")(3)
        Next i
    End With
lbl_Exit:
    Set oTable = Nothing
    Set oCell = Nothing
    Set oRng = Nothing
    Set oHeader = Nothing
    Set oColl = 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
 

Tags
cells, copy, table



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a text that's equal to "HELLO" in a table cell and copy the left side content. Underlined Purple Text and "formatted" boxes at side of document SeanCGR Word 1 06-20-2014 06:49 AM
How to edit the "Format" and the "show level" of an EXISTING table of content? Jamal NUMAN Word 2 08-14-2011 10:46 AM
Find a text that's equal to "HELLO" in a table cell and copy the left side content. "Table of content" based on "Normal Style" behavior!!!! Jamal NUMAN Word 4 07-08-2011 04:12 AM
Find a text that's equal to "HELLO" in a table cell and copy the left side content. Why the left edge of an inserted table is out "text boundary" by default? Jamal NUMAN Word Tables 2 06-30-2011 04:47 PM
How to have colons (:) in the "Table of content" but to be hidden in the "Heading"? Jamal NUMAN Word 0 06-26-2011 04:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:50 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