Skip to main content
andrewh37727702
Participant
April 29, 2016
Answered

Convert Excel formula to Javascript

  • April 29, 2016
  • 1 reply
  • 1446 views

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),68.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))))))

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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

1 reply

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
April 29, 2016

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

andrewh37727702
Participant
April 29, 2016

Looks good,

Thanks for the help.