【发布时间】:2017-03-22 21:01:37
【问题描述】:
我是 GAS 的新手,我正在尝试复制一些我在 Excel 中为我的 punting 组编写的 VBA 代码,以便可以在 Google 表格中使用它。鬼是……
- 我在一张纸上有一组 ID(交易)
- 我需要在第二张纸的范围内找到每个 ID(选择)
- 如果找到了 id,那么我需要检索一个偏移 $$ 值
- 如果没有找到 id,那么我需要检索值 $1
- 在检索到所有 $$ 值之后,我需要将它们相乘
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sel = ss.getSheetByName('selections'),
trn = ss.getSheetByName('transactions');
function calcPayout(a,b,inv) {
var data = sel.getRange("B3:B");
// find a in data, then return offset(0,2) as div1
// find b in data, then return offset(0,2) as div2
return div1 * div2 * inv
}
虽然我想将它自动化,以便与我创建的 Excel s/s 一样工作,但我很乐意使用 UDF,如上面的 sn-p 所示。
在 VBA 中,我使用以下内容来做同样的事情...
div1 = trn.Cells(i + 2, 11) // finds 'a' instead of user entering 'a'
div1 = data.Find(what:=div1).Offset(0, 2).Value
div2 = trn.Cells(i + 2, 12)
If opt2 = Empty Then GoTo calcLegReturn // calcReturn does 'return' calc
div2 = data.Find(what:=div2).Offset(0, 2).Value
谁能帮帮我?如果需要 this is a sample 了解 Google 表格的外观。
【问题讨论】: