2012-12-08 149 views
0

内执行计算我正在执行VB函数以在不同类别的指定期间内对累计金额进行分类。目标是为人事账户开支。VBA Excel在范围内查找日期期间并在

例如,我在表A中的某个日期,B列中的某个类别(例如Salary,Transport ...)和C列中的值中显示了“tmp”。

我要定义一个函数,我已经尝试设置:

Function Cumulatif(Categorie As String, Debut As Date, Fin As Date) As Double 
    ' Do the sum of a category between a starting and ending date specified 
    Dim Operations As Variant 
    Dim SpecificSum As Double 
    Dim i As Integer 
    Operations = ThisWorkbook.Sheets("tmp").Range("A1:C3") 
    For Each Row In Operations.Rows 
     SpecificSum = 0 
    Next 
    Cumulatif = SpecificSum 
End Function 

但我真的不知道如何从另一片得到的值,做循环中设置此金额范围内。有人可以帮助我吗?

+0

这样的函数返回#VALUE错误!我不明白为什么? – user1187727

+0

如果您希望将'Operations'分配为Range对象,那么您需要使用'Set'。如果你的意思是它是一个变种的二维数组(不使用set的话),那么就不会有'.Rows'集合...... –

回答

0
  1. 对操作的分配需要是一个对象赋值,意思是:使用Set(not Let/default)。

    Set操作= ThisWorkbook.Sheets( “TMP”)范围(“A1:C3)

  2. 你可以从其他表中的值(假设你的意思是 ”TMP“)如下

    SpecificSum = SpecificSum + Row.Cells(1, 1) 
    

我想你会更好,具有该功能需要一个额外的参数范围和供应工作表Sheet1 A作为一个参数;!当它需要重新计算这样Excel将知道

。 10

并调用使用这样一个公式Cumulatif:

=Cumulatif("hello9","10/1/2010", "10/31/2010",Sheet1!A2:A3) 
相关问题