How to handle ERROR .Find (). Column in VBA?

2

I have the following line of code:

columna_inicio = Range("4:4").Find(fecha).Column

The problem is that if date does not exist, the program releases an error.

How can I handle this?

I tried using the Try Catch but I can not get it to work. Also the On Error Go To ... but I can not make it work.

Any help?

The function to be implemented would be something like:

Public Function detectarfecha(fecha)

    Intenta 
    columna_inicio = Range("4:4").Find(fecha).Column

    Si no puede. Intenta 
    'Otra cosa...

End Function
    
asked by David_helo 27.07.2018 в 11:00
source

1 answer

4

You can use the On Error instruction as follows:

Public Function detectarfecha(fecha)
    On Error GoTo ErrorHandler

    columna_inicio = Range("4:4").Find(fecha).Column
    Exit Function
ErrorHandler:
    'Lo que necesites.
End Function

I hope it serves you.

    
answered by 27.07.2018 / 11:20
source