PDA

View Full Version : runtime error 13



elmnas
07-28-2015, 04:20 AM
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

jonh
07-28-2015, 07:05 AM
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)

elmnas
08-03-2015, 05:43 AM
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.