我在excel vba中寫了一個vba子例程,它總計出售給不同年份的客戶的lbs數量,並且出於某種原因,我得到了年度函數的編譯錯誤。有人能解釋爲什麼嗎?這裏是我的代碼:excel vba年度函數編譯錯誤
Private Sub lbsPerCustPerYear_Click()
Dim i As Integer
Dim Cust As String
Dim Cust2 As String
Dim Total As Integer
Dim Output As Range
Dim Output2 As Range
Dim Year1 As Date
Total = 0
Year1 = Range("K6").Value
Cust = Range("C6").Value
Cust2 = Range("C7").Value
Set Output = Sheets("Sheet2").Cells(2, 2)
Set Output2 = Sheets("Sheet2").Cells(2, 3)
For i = 1 To 14750
Year1 = Range("K5").Offset(i, 0).Value
If IsDate(Sheets("Sheet1").Cells(i, 11)) Then
If Cust = Cust2 And Year(Sheets("Sheet1").Cells(i, 11)) = 2012 Then
Total = Range("Q5").Offset(i, 0).Value + Range("Q6").Offset(i, 0).Value
Cust = Range("C5").Offset(i, 0).Value
Cust2 = Range("C6").Offset(i, 0).Value
Output.Value = Cust
Output2.Value = Total
Else
Cust = Range("C5").Offset(i, 0).Value
Cust2 = Range("C6").Offset(i, 0).Value
Year1 = Range("K5").Offset(i, 0).Value
Set Output = Output.Offset(1, 0)
Set Output2 = Output2.Offset(1, 0)
End If
Else
Cust = Range("C5").Offset(i, 0).Value
Cust2 = Range("C6").Offset(i, 0).Value
Year1 = Range("K5").Offset(i, 0).Value
Set Output = Output.Offset(1, 0)
Set Output2 = Output2.Offset(1, 0)
End If
Next i
End Sub
的錯誤是在該行:
If Cust = Cust2 And Year(Sheets("Sheet1").Cells(i, 11).Value) = 2012 Then
提前感謝!
這段代碼被編輯來解決這個問題,但是我現在得到了一行溢出錯誤:Total = Range(「Q5」)。Offset(i,0).Value + Range(「Q6」)。Offset i,0)。值 – ajs 2014-10-17 16:16:59