变体数组自定义函数Google表格?以VBA为例 [英] Variant Array Custom Function Google Sheets? VBA For Example

查看:78
本文介绍了变体数组自定义函数Google表格?以VBA为例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的以下函数将在Excel工作表的每一列中添加"1".如果我将= vbe(12)放在A1中,它将在"A1:L1"列中放入"1".如何将该VBA转换为适用于Google表格的JavaScript?

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

推荐答案

您可以编写一个自定义公式,该公式创建一个长度为指定参数的"1"数组,例如

function myFunction(numberColumns) {
  var ones=[];
  ones[0]=[];
  for(var i=0;i<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)

有用的信息可以在关于 Google表格中的自定义函数的文档中找到 Google Apps脚本.

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

这篇关于变体数组自定义函数Google表格?以VBA为例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆