|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 zhaogang1960 于 2014-5-17 18:55 编辑
kof369 发表于 2014-5-17 18:26
Sub Macro1()
Dim arr
arr = cal(2, 1, 1, 2)
向区域写数组公式:- Sub Macro1()
- 'Dim arr
- 'arr = cal(2, 1, 1, 2)
- ' Range("a1").Resize(, UBound(arr) - LBound(arr) + 1) = "=cal(2, 1, 1, 2)"
- Range("a1").Resize(, 2).FormulaArray = "=cal(2, 1, 1, 2)"
- End Sub
- Public Function cal(a As Integer, b As Integer, x As Integer, y As Integer) As Variant
- Dim c(1 To 4) As Integer
- Dim z() As Integer
- c(1) = a + b
- c(2) = a - b
- c(3) = a * b
- c(4) = a / b
- ReDim z(x To y)
- For i = x To y
- z(i) = c(i)
- Next
- cal = z
- End Function
复制代码 |
|