2 Replies Latest reply on Apr 29, 2016 12:07 PM by andrewh37727702

Convert Excel formula to Javascript

Hello,

Looking to convert these 2 formulas to work in Javascript.

=IF(D11=0,,IF(D11<=50,16.25,IF(AND(D11>=51,D11<=100),31.5,IF(AND(D11>=101,D11<=150),42.75, IF(AND(D11>=151,D11<=200),52.25,IF(AND(D11>=201,D11<=250),60.5,IF(AND(D11>=251,D11<=300),6 8.25,0)))))))

=IF(AND(D11>=301,D11<=350),75.25,IF(AND(D11>=351,D11<=400),82,IF(AND(D11>=401,D11<=450),82 ,IF(AND(D11>=451,D11<=500),94.75,IF(AND(D11>=501,D11<=1600),(D11*0.2),IF(D11>=1600,320,0)) ))))

• 1. Re: Convert Excel formula to Javascript

You may want to read up on the JavaScript core syntax. If you’ve managed to learn Excel macro programming, this should not be too complicated. Specifically, what you are looking for here is the if/else statement.

I've translated the first few cases of your first formula for you, you can now follow that pattern and add the remaining cases:

```var v = this.getField("D11").value;
event.value = 0;
if (v == 0) {
event.value = 0;
}
else if (v >=0 && v <= 50) {
event.value = 16.25;
}
else if (v > 50 && v <= 100) {
event.value = 31.5;
}
else if (...)
```

Here is a good resource to learn about JavaScript and Acrobat: Beginning JavaScript for Adobe Acrobat

• 2. Re: Convert Excel formula to Javascript

Looks good,

Thanks for the help.