Excel将范围传递给函数 [英] Excel passing a range into a function
本文介绍了Excel将范围传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将一系列单元格传递给函数,以便可以分别处理这些项目.因此,如何将一系列单元格传递给函数.
how do you go about passing a range of cells into a function so that you can then process the items separately. Therefore how do I pass a range of cells into a function.
我正在尝试这样做,所以我可以有一种使用以下方法的方法
I'm trying to do it so I can have a methods that uses the follow
Function processNumbers(Var as Range)
由此我不确定如何获取列表中的项目数以及如何遍历数组以编辑内容.是否有比以上更好的方式携带物品.
From this I'm not sure how I can get the number of items in the list and transverse the array to edit the contents. Is there a better way bring in the items than the above.
推荐答案
您声明的函数声明是正确的方法.
Your function declaration as stated is the correct way to do it.
Function processNumbers(Var as Range) As Variant
NumberOfCells = Var.Cells.Count
NumberOfRows = Var.Rows.Count
NumberOfColumns = Var.Columns.Count
RangeAddress = Var.Address
' Iterate the range (slow)
For Each Cl in Var.Cells
' ...
Next
' Get Values from range as an array
Dim Dat as variant
Dat = var
' Iterate array
For rw = LBound(Dat,1) to UBound(Dat,1)
For col = LBound(Dat,2) to UBound(Dat,2)
' reference Dat(rw,col)
Next col
Nest rw
' Put (modified) values back into range. Note: won't work in a UDF
Val = Dat
End Function
这篇关于Excel将范围传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文