2017-05-28 133 views
-1

我是VBA的新手,正在尝试为工作创建报表模板。我也想看看这是如何编码的,而不是使用一个公式。总结排除某些值的变量范围VBA

简而言之,我有一组变量值column A和日期column BColumn D是可变范围的日期(用户输入。我想有此作为我的代码内的阵列。)

我想总结column A同时排除在column D规定的日期,并具有该和输出到单元G1。下面附上了一张照片。

提前致谢!

Picture of the sheet

+0

你是怎么尝试**来编码的?它有用吗?如果没有,请显示您尝试的内容,我们可以帮助您解决问题。 – YowE3K

回答

0

试试这个代码,这是自我解释。

Sub sumVariables() 
Dim i As Long, j As Long, sum As Long, match As Boolean 
sum = 0 
match = False 
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row 
    For j = 2 To Cells(Rows.Count, 4).End(xlUp).Row 
     If Cells(i, 2) = Cells(j, 4) Then 
      match = True 
     End If 
    Next j 
    If match = False Then 
     sum = sum + Cells(i, 1) 
    End If 
    match = False 
Next i 
Cells(1, 7) = sum 
End Sub 

此代码将工作在您的工作表行的n个,并给予总在G1。让我知道你是否需要任何帮助。

+0

Hey Gowtham, 这工作完美。谢谢你的帮助! – ks9

+0

@ ks9 That's great .. –