Javascript to VBA

abinayadru

New Member
Joined
Jul 3, 2019
Messages
1
Hi Everyone,

I coded this following in adobe PDF using java script and I would now like to convert it into excel. Could you please help me with trying to convert this following code into VBA?
if (event.value == "Distribution") {
var cost = Number(this.getField("cost limit").valueAsString);
if (cost>=200001) {
this.getField("Sps").setItems(["Joe Doe"]);
} else {
this.getField("Sps").setItems(["Chris Worth"]);
}
}

Thank you very much.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
abinayadru,

I think the following is probably the code you are after. I am assuming that the construction
event.value ==
means that if there is a change on the sheet, and the changed cell contains...


In this case the following should work. It needs to be places in the sheet module for the sheet where the cell will be changed to 'Distribution'. To get there, right click on the sheet tab and select View Code...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Value = "Distribution" Then
        Range("Sps").Value = IIf(Range("cost limit").Value > 200001, "Joe Doe", "Chris Worth")
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top