If there's no underscore, then InicioCadena will equal 1. To be sure, change the UDF so it starts out at zero and only add one to it if it isn't equal to zero. Otherwise, exit with a simple error message.
Function extraecontrato(celda As range)
Dim InicioCadena, FinCadena As Double, Cadena...