How to avoid: Error of run Time '13'

D

dilettante

Hello,

I use follwing listing to insert two dates ina workbook:

Sub InserimentoPeriodo()
Dim DataInizio As Date
Dim DataFine As Date

If ActiveSheet.Name <> "Rates1" Then
Worksheets("Rates1").Activate
End If

DataInizio = InputBox("Inserisci la data di INIZIO periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "1-mag-1997")

If Year(DataInizio) <> 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E1").Value = DataInizio

DataFine = InputBox("Inserisci la data di FINE periodo nel formato
gg-mmm-aaaa", "Confronto Variazioni Prezzi", "10-set-1997")
If Year(DataFine) <> 1997 Then
MsgBox "Usare solo date dell'anno 1997", vbOKOnly
Exit Sub
End If
Range("E2").Value = DataFine

End Sub

If I answer to the imputbox question with "Cancel" I get the message:
Error of run Time '13'
How may avoid it?

Thank you for helping
 
J

JLGWhiz

One solution would be to use "On Error GoTo Next" (without the qotemarks)
just before your IF statement. Another would be to include another IF
statement that says
If Data Inizio = "" Then
(do something)
End If"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top