#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
See Conditionally Shade Table Cells in the Mailmerge Tips and Tricks Sticky thread at the top of this forum:
https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
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 |
#4
|
||||
|
||||
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 [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thanks for giving me so much input!
I shall try to figure it out now! |
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 |