0

I'm about to create a simple formular in WORD which is mainly based on a WORD table (not Excel table) in which I'd like to use if-statements.

As long as I deal with numbers everything works fine. But, as soon as I use characters I get the following error message: !Syntaxfehler, " (I work with a German version of WORD)

Here two examples, one with numbers, one with characters:

  1. Cell C4 of my table contains any number. If I use { =IF(C4=1;2;3) } (analoguously to EXCEL) I get 2, if C4 contains the number 1. If C4 contains any other number the code returns 3. So, everything is fine.

  2. But as soon as C4 contains a character (or string), say for example x and I use { =IF(C4="x";"YES";"NO") }, I get the above error message (instead of the hoped-for YES)

Anybody an idea what's going wrong here? Thanks!

jaysigg
  • 201
  • 1
  • 7

1 Answers1

0

Word's "field language" is very limited compared to the functions and operators available in Excel. Depending on what you're doing, the simplest thing may be to embed a suitable Excel sheet (or link to one).

The only type of field code that lets you reference a table cell (usually using A1-style notation) only works with numeric values in the cell. You can't for example, put "abc" in cell A1 of a table and use {=A1} to make a copy of that in another cell.

The {=} field essentially only works with numbers, not text or dates, and even the IF(,,) function in the {=} field onl allows numbers in all 3 of its parameters.

There are no text functions if the kind you will find in other languages (such as VBA) such as SUBSTRING, MID, LEN and so on. (except there is concatenation, in a sense, and there is something like a VBA LIKE operator).

So for example to do your { =IF(C4="x";"YES";"NO") } you have to do this:

  • Mark the content of cell C4 with a bookmark (let's call the bookmark "mybm").

  • use something like

    { IF "{ mybm }" = "x" "YES "NO" }

(some simplifications are possible in this case)

The problem with text comparisons with cell contents is that if you select the cell content and bookmark it, it's easy to delete the bookmark or, after editing the cell content, to end up with a situation where the bookmark does not actually reference the entire content of the cell. But nor can you get away with marking the entire cell either - the { IF } field just won't work.

For a numeric comparison, e.g. compare cell C4 with 1, but where you want a text result, you can either use an { IF } field (as above, not to be confused with the IF(,,) function), or you can use an { = } field where you specify the text results in a "numeric format". e.g.

{ IF {=C4} = 1 "one" "not one" }

or something like

{ =C4=1 \#"'one';;'not one'" }

All the {} have to be the special field code braces that yu can insert using e.g. ctrl-F9 on Windows desktop Word.

jonsson
  • 655
  • 1
  • 3
  • 10