13 Type mismatch error in IF statement

  • Hi,
    We have VBA code to copy data from Tab01 to Tab02 filtered by some conditions.


    If wks.Range("ActualCost").Rows(r) - dblCapital < 0 Then
    Me.Cells(ROut, 28) = "Under by " & Format(wks.Range("ActualCost").Rows(r) - dblCapital, varCurrency)
    ElseIf Abs(dblCapital - wks.Range("ActualCost").Rows(r)) > dblCapital * 0.03 Then
    Me.Cells(ROut, 28) = "Over by " & Format(wks.Range("ActualCost").Rows(r) - dblCapital, varCurrency)
    Me.Cells(ROut, 28).Interior.Color = ErrorColor
    Else
    Me.Cells(ROut, 28) = "OK"
    End If


    I have 2 rows for data copy, but getting the error only for 1 row. I am getting 13 Type mismatch error on the IF statement "If wks.Range("ActualCost").Rows(r) - dblCapital < 0 Then"


    1. wks.Range("ActualCost").Rows(r) = [Blank] , dblCapital = 87000
    2. wks.Range("ActualCost").Rows(r) = [Blank] , dblCapital = 125000


    1st set of values

    • If statement is executing without any issues.
    • Debug.Print "ActualCost: " & wks.Range("ActualCost").Rows(r) is giving blank/no values
    • when i take the cuser wks.Range("ActualCost").Rows(r) its not showing any values.

    2nd set of values

    • If statement erroring out with 13 Type mismatch error
    • Debug.Print "ActualCost: " & wks.Range("ActualCost").Rows(r) is giving blank/no values
    • when i take the cuser wks.Range("ActualCost").Rows(r) its showing " ".
    • When i copy the format of the wks.Range("ActualCost").Rows(r) cell from the 1st row to the 2nd row, the if statement is executing without any errors


    How can i resolve this issue


    Thanks

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!