Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-11-2015, 01:11 PM
KeithLee22 KeithLee22 is offline Using VBA to Compare and Highlight words in a Word Table's Row/Cell Windows 8 Using VBA to Compare and Highlight words in a Word Table's Row/Cell Office 2010 32bit
Novice
Using VBA to Compare and Highlight words in a Word Table's Row/Cell
 
Join Date: Nov 2015
Posts: 2
KeithLee22 is on a distinguished road
Default Using VBA to Compare and Highlight words in a Word Table's Row/Cell

Hello,




I'm looking for some assistance with a issue I'm having using VBA.

I have a Table (2 Columns and hundreds of Rows) and I want to Compare the individual words in each Row (Column #1 of Row #1) against the individual words in (Column #2 of Row #1) and if there are "Duplicate Words in each Column (Capitalization does not matter) I want the words "Highlighted". Each successive Row will be compared against that Row's 2 Columns only.

please see attachment sample table graphic.

Any help would be greatly appreciated.

Keith
Attached Images
File Type: jpg sample-table.jpg (221.2 KB, 22 views)
Reply With Quote
  #2  
Old 11-11-2015, 02:53 PM
macropod's Avatar
macropod macropod is offline Using VBA to Compare and Highlight words in a Word Table's Row/Cell Windows 7 64bit Using VBA to Compare and Highlight words in a Word Table's Row/Cell Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, Rng As Range, strTxt As String, i As Long, j As Long
Options.DefaultHighlightColorIndex = wdYellow
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      For i = 1 To .Rows.Count
        Set Rng = .Cell(i, 2).Range
        With .Cell(i, 1).Range
          For j = 1 To .Words.Count
            strTxt = Trim(.Words(j))
            With Rng.Find
              .ClearFormatting
              .Text = strTxt
              With .Replacement
                .ClearFormatting
                .Highlight = True
                .Text = "^&"
              End With
              .Format = True
              .Forward = True
              .MatchCase = False
              .MatchWholeWord = True
              .MatchWildcards = False
              .Wrap = wdFindStop
              .Execute Replace:=wdReplaceAll
            End With
          Next
        End With
      Next
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
Note that the above code searches for everything VBA regards as a 'word'. That includes punctuation.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-11-2015, 03:37 PM
KeithLee22 KeithLee22 is offline Using VBA to Compare and Highlight words in a Word Table's Row/Cell Windows 8 Using VBA to Compare and Highlight words in a Word Table's Row/Cell Office 2010 32bit
Novice
Using VBA to Compare and Highlight words in a Word Table's Row/Cell
 
Join Date: Nov 2015
Posts: 2
KeithLee22 is on a distinguished road
Default

Thank You Very Much...
Reply With Quote
Reply

Tags
compare, duplicates, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VBA to Compare and Highlight words in a Word Table's Row/Cell Find and highlight multiple words in MS Word document AtaLoss Word VBA 37 09-22-2021 12:04 PM
Word tables: prevent word from highlighting whole cell when I highlight text skylark53 Word 2 08-04-2015 08:12 AM
Using VBA to Compare and Highlight words in a Word Table's Row/Cell Highlight Words from a Word List JSC6 Word VBA 1 09-30-2014 08:22 PM
Adapt a script used in Word to highlight words, to work in Outlook? flatop Outlook 5 07-15-2014 01:07 PM
permanently highlight searched words in word 2013 arjay Word 4 08-16-2013 09:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:15 AM.


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