Conditional formating in word document - vba

I am distributing some variables from excel to word. Now, I would like to put a conditional formatting in some fields. The normal situation that is working fine is this field:
{DOCVARIABLE AB*MERGEFORMAT}
Now, I want to apply condition to AB. For example, if AB < 1 it is highlighted as green and if it is AB>1 it highlighted as red. I tried different variations, but all of them was wrong. For example, 2 of them are these:
1- {If {DOCVARIABLE AB*MERGEFORMAT}> "1" {DOCVARIABLE AB*MERGEFORMAT} {DOCVARIABLE AB*MERGEFORMAT}}
2- {If <<DOCVARIABLE AB*MERGEFORMAT>> > "1" {DOCVARIABLE AB*MERGEFORMAT} {DOCVARIABLE AB*MERGEFORMAT}}
And I am highlighting the middle part as red and the last part as green. But it gives me the error that the operation is unknown, so the if function is not written in a proper way.

Although conditional formatting does not exist in Word it is possible to approximate it for very simple conditions. For further information see the documentation for IF field

Related

Conditional Merge in Word is adding an Extra character "I" before each conditional paragraph

I am doing a conditional merge in Word from an excel list. One of the conditions is If Program Restriction = XYZ, then add this paragraph. If Program Restriction = ABC, then add this paragraph.
For the first letter, it adds the paragraph perfectly. From that point on, it will add an "I" in front of the paragraph for all addition conditional paragraphs.
Here is the conditional Merge formatting:
Can anyone tell me why this is doing that? I checked the document to ensure I do not have an "I" anywhere in the document that could be throwing off the code.
Any help is so appreciated.
Thanks
Cathy
I have tried seeing if there is conditional coding that contains the character. It does not.
I have tried seeing if there is an "I" in the previous fields to see if that is throwing it off. there is not.

In Google Spreadsheets, how to ignore empty cells in conditional formatting?

I'm trying to format a spreadsheet to change cell color to green/red if the result was predicted correctly/incorrectly. For the correct one, I just went with =(cell with the results)=(cell where the prediction is) and it's all fine, but for the incorrect ones, I had to do NOT(same formula I just wrote) and it tries to color every cell red, even those that haven't had a prediction typed in yet, because there can be multiple bad outcomes. How to ignore conditional formatting before the result is typed into the "result" cell?
The ISBLANK function returns true if the referenced cell is blank, and false otherwise. You can use this in the custom formula to require that both the value is incorrect and the cell is not blank. That is,
=AND([your current formula], NOT(ISBLANK([cell with the results])))
Alternatively, you could add another formatting rule. There's an "Is empty" option for conditional formatting, and the formatting style would be no color. Make sure to put this rule above the red rule.

Excel: Highlighting duplicates with exact matches

I've got two columns of data, and I would like to use conditional highlighting to find the EXACT matches in both columns. However, using a formula like this one turns up a lot of incorrect matches:
=MATCH(A1,B:B,0)>0
There are a lot of partial matches, so cells are highlighted that I don't want. What I want is the equivalent of the "Match Entire Cell Contents" checkbox in the Find & Replace dialog.
To make this clear, it seems Excel will do partial matches - here is the Find & Replace dialog without "Match Entire Cell Contents" checked, with a sample search for all matches:
Search for all matches, any match
Vs. the dialog with the checkbox ticked and the results:
Search for all matches, match entire cell
But this only applies to find & replace. How can I update the formula above to work the same way, so that only exact matches to what's in a cell are highlighted?
=NOT(ISERROR(MATCH(A1,B:B,0)))
Regular use of MATCH() - without wildcards - doesn't do partial matches, and MATCH returns an error if there's no hit, not zero
This isnt quite what is being asked, but this was helpful to me:
To find duplicate records, use Excel's easy-to-use Filter feature as follows:
Select any cell inside the recordset.
From the Data menu, choose Filter and then select Advanced Filter to open the Advanced Filter dialog box.
Select Copy To Another Location in the Action section.
Enter a copy range in the Copy To control.
Check Unique Records Only and click OK.
There's more about conditional formatting on this site:
https://www.techrepublic.com/blog/windows-and-office/how-to-find-duplicates-in-excel-245163/

If content in a cell is too long, show "Multiple" instead of letting the text overflow in Excel

So, I have a custom function that concatenate different cells and put a comma between words.
For example, say I have "ABCD" "BC" then, this function will
output ABCD, BC. Now the problem is that the text will overflow in a cell and overlap with the cell next to that. In order to solve this problem,
I am thinking of just replacing the concatenated word with "Multiple" if more than 3 words are combined. Is there anyway to do this in a cell?
You can do this with conditional formatting AND keep the original underlying string as a raw value for other purposes.
Select the cells with the formula and create a conditional formatting rule based on a formula.         =LEN(C2)-LEN(SUBSTITUTE(C2, ",", ""))>1 
Click Format and go to the Numbers tab. Choose Custom from the list down the left side and supply the following for the Type:         ;;;[color13]_((\multipl\e)   I've opted to also make the font dark blue (colorindex # 13) and indent from the left.
Click OK to accept the formatting and then OK again to create the new rule.
        
As you can see in the sample image above, the underlying raw value remains (shown in the formula bar) but (multiple) is displayed.
More on custom number formatting codes at Number format codes

Change #N/A to Blank cell

How can I change the #N/A to the blank cell if nothing in that cell?
Eg. =VLOOKUP(B19:B36;$TABLE.A1:C46;2;0)
I think I might need something like an ISERROR check but I don't 100% know what I'm doing.
If we're talking about Excel 2010 and later you can use IFERROR:
=IFERROR(VLOOKUP(B19:B36;$TABLE.A1:C46;2;0);"")
You can also put text into the final string result
The question was misleading about the spreadsheet software as 2 different spreadsheets were originally stated in tags. However, it can be seen that the question is about OpenOffice Calc:
- Absolute sheet referencing ($ sign before the sheet name) is not possible in Excel.
- We also see a dot between the sheet name and the range, which is again not possible in Excel.
As in OpenOffice Calc you don't have IFERROR function, the only way is to repeat your main function twice in the following form (you can use both, ISNA and ISERROR, but I suggest ISNA as it's more specific and fits your case):
=IF(ISNA(YourFormula);"";YourFormula)
In your case something like:
=IF(ISNA(VLOOKUP(B19;$TABLE.A1:C46;2;0));"";VLOOKUP(B19;$TABLE.A1:C46;2;0))
You may want to make absolute reference to the range where you look for matching values, as I see you want to copy the formula down.
=IF(ISNA(VLOOKUP(B19;$TABLE.$A$1:$C$46;2;0));"";VLOOKUP(B19;$TABLE.$A$1:$C$46;2;0))
Since the cells will contain a formula this is about appearances, so Conditional formatting might suit, say if the cell background is white, for style choose Font > Font Effects > Font color white.
For this, select the relevant range - I have assumed D19:D36 - and Format > Conditional Formatting... and for Condition 1 choose Cell value is and equal to and:
ISNA(D19)