2017-05-28 128 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 .. –