Google Sheets的变体数组自定义函数?例如VBA。

huangapple go评论85阅读模式
英文:

Variant Array Custom Function Google Sheets? VBA For Example

问题

以下是将VBA代码翻译成JavaScript代码的部分:

function vbe(Num) {
   var ary = [];
   for (var i = 0; i < Num; i++) {
      ary.push(1);
   }
   return ary;
}

希望这对您有所帮助。如果您需要进一步的翻译,请告诉我。

英文:

The following function below will add "1" to every column across the excel sheet. If I put =vbe(12) in A1, it will put "1" in columns "A1:L1". How can I translate this VBA to JavaScript for Google Sheets?

Function vbe(Num As Long) As Variant
   Dim ary As Variant
   Dim i As Long
   ReDim ary(Num - 1)
   For i = 0 To Num - 1
      ary(i) = 1
   Next i
   vbe = ary
End Function

Google Sheets的变体数组自定义函数?例如VBA。

答案1

得分: 1

你可以编写一个自定义公式,根据指定的参数创建一个包含 "1" 的数组,例如:

function myFunction(numberColumns) {
  var ones=[];
  ones[0]=[];
  for(var i=0;i<numberColumns;i++){
    ones[0].push(1);
  }
  return ones;
}

现在,你只需要在单元格中调用该函数,例如输入:

=myFunction(12)

有关在Google Sheets中使用自定义函数的有用信息可以在Google Sheets自定义函数文档Google Apps脚本文档中找到。

英文:

You can write a custom formula that creates an array of "1"s with the length as a specified parameter, e.g.

function myFunction(numberColumns) {
  var ones=[];
  ones[0]=[];
  for(var i=0;i&lt;numberColumns;i++){
    ones[0].push(1);
  }
  return ones;
}

Now, you just need to call the function from a cell, e.g. by typing

=myFunction(12)

Useful information can be found in the documentation about Custom Functions in Google Sheets and Google Apps Script.

huangapple
  • 本文由 发表于 2020年1月3日 22:19:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定