Я продолжаю получать сообщение об ошибке 13 - несоответствие типов в следующей строке:
MonthsWithValues = Application.WorksheetFunction.CountIfs(Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24)), Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24)).Value <> 0, Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24)), Not IsEmpty(Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24))))
в функции ниже. Может ли кто-нибудь помочь мне исправить этот код? Спасибо!!
Код:
Function NextYearFigures()
With Worksheets("Analysis Worksheet")
Dim i As Long
Dim MonthsWithValues As Long
Dim LastRow As Long
LastRow = Range("X" & Rows.Count).End(xlUp).Row
For i = 5 To LastRow
MonthsWithValues = Application.WorksheetFunction.CountIfs(Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24)), Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24)).Value <> 0, Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24)), Not IsEmpty(Worksheets("Analysis Worksheet").Range(.Cells(i, 13), .Cells(i, 24))))
If .Range("X" & i).Value > 0 And Not IsEmpty(Worksheets("Fixed Cost Test Data").Range("B" & i).Value) _
And Worksheets("Fixed Cost Test Data").Range("C" & i).Value <= #11/30/2016# Then
.Range("Z" & i).Value = ((Orig2016Total - (Worksheets("Fixed Cost Test Data").Range("B" & i).Value * (12 - (Left(Worksheets("Fixed Cost Test Data").Range("C" & i).Value, 2))))) / MonthsWithValues) + Worksheets("Fixed Cost Test Data").Range("B" & i).Value
ElseIf .Range("X" & i).Value > 0 And Not IsEmpty(Worksheets("Fixed Cost Test Data").Range("B" & i).Value) _
And Worksheets("Fixed Cost Test Data").Range("C" & i).Value > #11/30/2016# Then
.Range("Z" & i).Value = (Orig2016Total - (Worksheets("Fixed Cost Test Data").Range("B" & i).Value * (12 - (Left(Worksheets("Fixed Cost Test Data").Range("C" & i).Value, 2))))) / MonthsWithValues
ElseIf .Range("X" & i).Value > 0 And IsEmpty(Worksheets("Fixed Cost Test Data").Range("B" & i).Value) Then
.Range("Z" & i).Value = (Orig2016Total - (Worksheets("Fixed Cost Test Data").Range("B" & i).Value * (12 - (Left(Worksheets("Fixed Cost Test Data").Range("C" & i).Value, 2))))) / MonthsWithValues
ElseIf .Range("X" & i).Value = Worksheets("Fixed Cost Test Data").Range("B" & i).Value Then
.Range("Z" & i).Value = ((Orig2016Total - (Worksheets("Fixed Cost Test Data").Range("B" & i).Value * (12 - (Left(Worksheets("Fixed Cost Test Data").Range("C" & i).Value, 2))))) / MonthsWithValues) + Worksheets("Fixed Cost Test Data").Range("B" & i).Value
ElseIf IsEmpty(.Range("X" & i).Value) Or .Range("X" & i).Value = 0 Then
.Range("Z" & i).Value = (Orig2016Total - (Worksheets("Fixed Cost Test Data").Range("B" & i).Value * (12 - (Left(Worksheets("Fixed Cost Test Data").Range("C" & i).Value, 2))))) / MonthsWithValues
End If
Next i
End With
End Function