Rajouter msgBox en cas d'erreur
J
Bonjour,
Comme le nom de la feuille cible est généré par une comboBox, je souhaiterais rajouter un petit MsgBox au cas ou cete combobox soit mal renseignée.
Donc juste après
With Workbooks("tableau bord.xls").Sheets(Feuille)J'ai essayéOn error GoTo.. mais je n'y parviens pas
Merci
Private Sub CommandButton5_Click()
Workbooks.Open Filename:=ThisWorkbook.Path & "\tableau bord.xls"
For Each W In Workbooks
Feuille = ComboBox1.Value
If W.Name = "tableau bord.xls" Then
With Workbooks("tableau bord.xls").Sheets(Feuille)
Ln = .Range("B" & Rows.Count).End(xlUp).Row + 1
.Range("B" & Ln).Value = TextBox15identificationéquipe.Value
.Range("C" & Ln).Value = TextBox1.Value
.Range("D" & Ln).Value = TextBox8gdma.Value
.Range("E" & Ln).Value = TextBox6lieutravaux.Value
.Range("F" & Ln).Value = TextBox6.Value
End With
ActiveWorkbook.Save
MsgBox "Tableau bord renseignée"
End
End If
Next W
MsgBox "Vous devez ouvrir votre classeur ''tableau bord'' !", 16
End SubBonsoir
A tester (mais sans les fichiers à tester pas facile )
Private Sub CommandButton5_Click()
On Error GoTo YaErreur
Workbooks.Open Filename:=ThisWorkbook.Path & "\tableau bord.xls"
For Each W In Workbooks
Feuille = ComboBox1.Value
If W.Name = "tableau bord.xls" Then
With Workbooks("tableau bord.xls").Sheets(Feuille)
Ln = .Range("B" & Rows.Count).End(xlUp).Row + 1
.Range("B" & Ln).Value = TextBox15identificationéquipe.Value
.Range("C" & Ln).Value = TextBox1.Value
.Range("D" & Ln).Value = TextBox8gdma.Value
.Range("E" & Ln).Value = TextBox6lieutravaux.Value
.Range("F" & Ln).Value = TextBox6.Value
End With
ActiveWorkbook.Save
MsgBox "Tableau bord renseignée"
End
End If
Next W
MsgBox "Vous devez ouvrir votre classeur ''tableau bord'' !", 16
Exit Sub
YaErreur:
MsgBox "Erreur " & Err.Number & vbLf & Err.Description
End SubJ
Une fois de plus... MERCI!!
Bonsoir,
bonsoir Banzaï
Private Sub CommandButton5_Click()
Workbooks.Open Filename:=ThisWorkbook.Path & "\tableau bord.xls"
For Each W In Workbooks
Feuille = ComboBox1.Value
If W.Name = "tableau bord.xls" Then
With Workbooks("tableau bord.xls")
on error goto terreur
with .Sheets(Feuille)
on error goto 0
Ln = .Range("B" & Rows.Count).End(xlUp).Row + 1
.Range("B" & Ln).Value = TextBox15identificationéquipe.Value
.Range("C" & Ln).Value = TextBox1.Value
.Range("D" & Ln).Value = TextBox8gdma.Value
.Range("E" & Ln).Value = TextBox6lieutravaux.Value
.Range("F" & Ln).Value = TextBox6.Value
End With
end with
ActiveWorkbook.Save
MsgBox "Tableau bord renseignée"
End
End If
Next W
MsgBox "Vous devez ouvrir votre classeur ''tableau bord'' !", 16
ici:
on error goto 0
exit sub
terreur:
msgbox "feuille inexistante"
resume ici
End Sub