#1
|
|||
|
|||
Tables withmergefields, if statement and calculations.
Hi,
I am currently working with a table in Word which forms part of invoice. The invoice makes use of a table within word and pulls data into Word using merge fields. At this point in time it uses merge fields to pull in the description of a fee and the date of the transaction in column a and the gross amount of the fee in column C. What I'd like to do is split off the VAT element into column B. As VAT is not always 20% I need to search the value within the description merge field in column A for the VAT amount to be applied: Example of fee description: 05 Jun 2014 - 60% Take On Fee (£84.00 + VAT @ 20%) What I'd like to do is add an if statement in column B which checks the description for "+ VAT @ 20%" if it finds this value then to take the value from column C and get the VAT component as the value in column B. Else if the "+VAT @ 5%" then split off 5% VAT into column B Else add 0.00 as value within column B. If this could be achieved it would be an absolute life saver. Any help would be greatly appreciated. |
#2
|
||||
|
||||
Word fields can't really do any meaningful string testing for parts of a string and are even more limited for string splitting. That said, it would be possible to test whether the field ends with 5%, for example, and vary where the whole of the output for that field goes, accordingly.
So, if your field outputs '£84.00 + VAT @ 20%', or '£84.00 + VAT @ 5%', you could use two fields, to conditionally output the whole field in either column: {IF{MERGEFIELD Amount}= "*20%" {MERGEFIELD Amount}} {IF{MERGEFIELD Amount}= "*5%" {MERGEFIELD Amount}} or: {IF«Amount»= "*20%" «Amount}} {IF«Amount»= "*5%" «Amount}} where 'Amount' is your mergefield's name Splitting the output components is more complicated, involving some circumlocution. The following will return the £ values: {IF{MERGEFIELD Amount}= "*20%" {={MERGEFIELD Amount}-.2 \# "£,0.00"}} {IF{MERGEFIELD Amount}= "*5%" {={MERGEFIELD Amount}-.05 \# "£,0.00"}} or: {IF«Amount»= "*20%" {=«Amount»-.2 \# "£,0.00"}} {IF«Amount»= "*5%" «Amount»-.05 \# "£,0.00"}} The following will return the % portions: {IF{MERGEFIELD Amount}= "*20%" "+ VAT @ 20%"} {IF{MERGEFIELD Amount}= "*5%" "+ VAT @ 5%"} or: {IF«Amount»= "*20%" "+ VAT @ 20%"} {IF«Amount»= "*5%" "+ VAT @ 5%"} Note: The field brace pairs (i.e. '{ }') for the above examples are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practicable to add them via any of the standard Word dialogues. Likewise, you can't type or copy & paste the chevrons (i.e. '« »') - they're part of the actual mergefields, which you can insert from the mailmerge toolbar. The spaces represented in the field constructions are all required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Prefect!
Perfect that has resolved the problem. Thanks for your help.
|
Tags |
mergefields, ms word, tables |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tiered Fee Calculations | lynchbro | Excel | 5 | 07-17-2014 11:01 AM |
Table Calculations, VBA | SuzeG | Word VBA | 7 | 12-15-2013 07:12 PM |
How to do Calculations In a Text Box? | SteveF | Word | 4 | 09-27-2013 08:34 AM |
Using Reference Tables in calculations | BritBiker2 | Excel | 5 | 02-15-2013 04:19 AM |
Can I do calculations with times? | cubsfan_1 | Excel | 1 | 01-14-2010 06:55 PM |