Bonjour,
J'ai un problème avec mon code qui concerne la gestion des erreurs (quand je clique sur le bouton cancel ou sur la croix du haut à droite de l'inputbox) avec une application.inputbox lors de l'enregistrement d'un Array :
Option Explicit
Sub Try1()
Dim ARR1() As Variant
Dim i As Long
Dim RNG1 As Range
Dim ANSWER1 As VbMsgBoxResult
ThisWorkbook.Worksheets("Sheet10").Select
StartAgain1:
On Error GoTo Handler1
ARR1 = Application.InputBox(prompt:="Select the Range that you want to pass in the Array.", Type:=64)
On Error GoTo 0
For i = LBound(ARR1, 1) To UBound(ARR1, 1)
ARR1(i, 1) = Int(ARR1(i, 1) / 60) & "h " & ARR1(i, 1) Mod 60 & "mn"
Next
Set RNG1 = Application.InputBox(prompt:="Select the cell that will serve as the first cell of the array.", Type:=8)
Range(RNG1, RNG1.Offset(UBound(ARR1, 1) - 1, 0)) = ARR1
Handler1:
If Err.Number = 13 Then
ANSWER1 = MsgBox(prompt:="Do you want to retry?", Title:="JMC Inc.", Buttons:=vbYesNo + vbQuestion)
If ANSWER1 = vbYes Then
GoTo StartAgain1
Else
Exit Sub
End If
End If
Erase ARR1
End Sub
Lorsque je clique lors du premier passage sur le bouton "Cancel" de mon inputbox, mon code passe bien par "Handler1" avec la msgbox qui me demande si je veux refaire un essai. Mais lors de ce 2ème essai, si je re-clique sur le bouton "Cancel", mon code ne repasse pas par "Handler1", et j'ai un message "Run-Time error 13" qui s'affiche. Pourquoi l'erreur "Run-Time error 13" est traitée lors de la première fois, mais pas lors de la deuxième fois ? Cela m'intrigue... Merci d'avance pour vos explications...!