在Excel中检索条件中的细胞数量
我需要检索一些单元格号码以用于其他function。
基本上,我需要一个函数,可以testing一个条件,并检索行号,然后可以添加我select的列字母。 该函数的forms为getcolnumbers(range;criteria;'column_letter_to_be_appended_to_the_numbers_retrieved')
Eg: =getcolnumbers(A1:A10;5130;'B') Ans: If the condition is satisfied in A3,A5,A8, then the return value should be 'B3;B5;B8'
Excel中有这样一个函数吗?
您可以创build自己的用户定义的function:
Public Function getcolnumbers(r1 As Range, v As Variant, colid As String) As String Dim r As Range getcolnumbers = "" For Each r In r1 If r.Value = v Then getcolnumbers = getcolnumbers & ";" & colid & r.Row End If Next r If Len(getcolnumbers) > 1 Then getcolnumbers = Mid(getcolnumbers, 2) End Function
例如:
用户定义的函数(UDF)非常易于安装和使用:
- ALT-F11调出VBE窗口
- ALT-I ALT-M打开一个新的模块
- 粘贴东西,closuresVBE窗口
如果保存工作簿,则UDF将随之保存。 如果您在2003年以后使用的是Excel版本,则必须将该文件另存为.xlsm而不是.xlsx
要删除UDF:
- 如上所示调出VBE窗口
- 清除代码
- closuresVBE窗口
从Excel中使用UDF:
= myfunction的(A1)
要了解有关macros的更多信息,请参阅:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
和
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
有关UDF的具体信息,请参阅:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
macros必须启用这个工作!
(注意:在工作表单元格中input公式时,可能需要使用分号代替逗号)
最简单的方法可能是将您的过程分解为其他列。 例如,添加一列C,其中
C1 = if(A1 > 5130, B1, "")
然后,列C将只包含您想要的列B的值,根据您给列A的条件。