Consulting

Results 1 to 3 of 3

Thread: runtime error 13

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    114
    Location

    runtime error 13

    Hello people I have made following code but It was a time ago...

    I get error: Runtime error 13 : incompatible types

    see code below

    Sub CheckIND()
    
    'IND=IND CHECK FIL;;;;;;;;;;;;;;;;;;;;;;
    For I = 2 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).row
        If Cells(I, "J") = "IND" And Cells(I, "K") = "IND" And Len(Cells(I, "B")) <> 0 And Cells(I, "AB") <> 0 Then
        Cells(I, 1).EntireRow.Interior.ColorIndex = 6
        mycell = Cells(I, "B").Text
        mycellRes = mycell - 1
        DivAB = Cells(I, "AB").Text
        myTot = Round(DivAB / mycellRes)
        ValueSought = Cells(I, "A").Value
        Set FirstInstance = Columns("A").Find(what:=ValueSought, LookIn:=xlFormulas, LookAt:=xlWhole, SearchFormat:=False)
            If Not FirstInstance Is Nothing Then Set RangeToSearch = Range(FirstInstance, Cells.SpecialCells(xlCellTypeLastCell)).Columns(1)
            RangeToSearchFirstRow = FirstInstance.row
            RangeToSearchValues = RangeToSearch.Value
            Set RangeToUpdate = FirstInstance
            For j = 1 To UBound(RangeToSearchValues)
            If RangeToSearchValues(j, 1) = ValueSought Then
            Set RangeToUpdate = Union(RangeToUpdate, Cells(j - 1 + RangeToSearchFirstRow, "A"))
            End If
        Next j
        RangeToUpdate.Offset(, 19).Value = myTot
        End If
    Next I
    End Sub
    when I see troubleshoots the problem the error is:
    myTot = Round(DivAB / mycellRes)
    Could someone help me ?

    Thank you in advance

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    DivAB is a variant since it's not been declared, and you're setting it to a string value.

    Either declare it as a number type, convert it's source or preferably both.

    DivAB = cdbl(Cells(I, "AB").Text)

  3. #3
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    114
    Location
    Quote Originally Posted by jonh View Post
    DivAB is a variant since it's not been declared, and you're setting it to a string value.

    Either declare it as a number type, convert it's source or preferably both.

    DivAB = cdbl(Cells(I, "AB").Text)
    oww thank you sir.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •