Excel VBA - Erro em tempo de execução 13 - Tipo incompatível

0

Continuo recebendo o erro de tempo de execução 13 - incompatibilidade de tipo na linha a seguir:

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))))

na função abaixo. Alguém poderia me ajudar a corrigir esse código? Obrigado !!

Código:

    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
    
por HeatherD 24.03.2016 / 22:18

0 respostas