Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Mail Merge

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 01-15-2018, 12:45 PM
sophiebatch sophiebatch is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2018
Posts: 2
sophiebatch is on a distinguished road
Question Conditional formating table


Hi there,

I'm using a word template together with an online based inventory management system. It allows me to print out picking lists etc. I was wondering if I could manipulate the information so that depending on a prefix the font is changing. So if I have "IH1-" in one row it would automatically write it in red or write it in bold.
I've attached the word document we're using which should make it easier to undertstand On the word document the cell I'm refering to is code <<Product Code>> Plus you can also find the finished pdf. file.

Hope some one knows if it's possible. Also just a little hint to the right direction would be more then I can ask for.

Many thanks,

Sophie
Attached Files
File Type: docx BatchOrganics 1.docx (44.9 KB, 11 views)
File Type: pdf Batch1 SO-00384 for SophieSchrittenloher (1).pdf (63.1 KB, 4 views)
Reply With Quote
  #2  
Old 01-15-2018, 02:12 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,199
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

See Conditionally Shade Table Cells in the Mailmerge Tips and Tricks Sticky thread at the top of this forum:
http://www.msofficeforums.com/mail-m...ps-tricks.html
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-18-2018, 05:12 PM
kilroy kilroy is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 62
kilroy is on a distinguished road
Default

Based on the Word document you supplied the following code allows you to choose the text you want to find and choose the column it looks in. I'm sure it could probably be cleaned up. I believe this code was originally written by Greg Maxey but butchered by me to suit your needs.

Code:
Sub BoldRowBasedOnString()
 
Dim strName As String
Dim oDoc As Document
    Dim oTbl As Table
    Dim oCell As Cell
    Dim oRow As Row
    Dim strText As String, strRef As String
    Dim lngCol As Long
    Dim oRng As range
    Set oDoc = ActiveDocument
    Set oTbl = oDoc.Tables(2)
    strText = InputBox("Search text?")
    lngCol = CLng(InputBox("Enter column to search", "Must be 1 - 5"))
    For Each oCell In oTbl.range.Cells
    If oCell.RowIndex > 1 And oCell.ColumnIndex = lngCol Then
            On Error Resume Next
            If Left(oTbl.Cell(oCell.RowIndex, 1).range.Text, Len(oTbl.Cell(oCell.RowIndex, 1).range.Text) - 2) <> vbNullString Then
                strRef = Left(oTbl.Cell(oCell.RowIndex, 1).range.Text, Len(oTbl.Cell(oCell.RowIndex, 1).range.Text) - 2)
            End If
            If Left(oTbl.Cell(oCell.RowIndex, 1).range.Text, Len(oTbl.Cell(oCell.RowIndex, 1).range.Text) - 2) = vbNullString Then
                oTbl.Cell(oCell.RowIndex, 1).range.Text = strRef
            End If
            On Error GoTo 0
            If InStr(UCase(oCell.range.Text), UCase(strText)) > 0 Then
               oCell.range.Select
               With Selection
                  Selection.SelectRow
                  Selection.BoldRun
               End With
            End If
    End If
    Next
lbl_Exit:
    Set oDoc = Nothing: Set oTbl = Nothing: Set oCell = Nothing
    Exit Sub
    End Sub
Reply With Quote
  #4  
Old 01-18-2018, 06:09 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,199
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Since the document is for use with a mailmerge, I can't see the point of running a macro when the highlighting can be done during the merge itself; the macro would have to be run on the output document after the merge has been executed, thus adding an extra step to the process.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 02-14-2018, 08:09 AM
sophiebatch sophiebatch is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2018
Posts: 2
sophiebatch is on a distinguished road
Default

Thanks for giving me so much input!

I shall try to figure it out now!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional formating SHolm Outlook 1 01-09-2018 08:37 PM
Conditional Formating? wilabern Excel 6 12-13-2017 10:08 AM
Conditional formating MJS16 Excel 16 12-01-2016 01:09 PM
Conditional Formating Aseren Excel 14 02-18-2016 01:05 PM
more Conditional Formating princeofsadness Excel 2 09-05-2011 02:14 AM


All times are GMT -7. The time now is 07:26 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft