gestion d'erreurs

  • Initiateur de la discussion Reeaz
  • Date de début
R

Reeaz

Guest
Rebonjour,

J'ai crée une macro qui me renvoie des chiffres ds la collonne 11 en référence à la collonne 7. Cependant ds ma collonne 7, il y a des erreurs du type #N/A (div pa 0).Je voudrai que ma macro ne stoppe pas quand elle arrive à ce type de cellule et qu'elle renvoie rien ds la collonne 11. J'ai essayé ce qui suit mais la macro me renvoie des 1 ds la collonne 11 et je voudrai qu'elle ne me renvoie rien du tout:


Sub Chiffre1()

fin = Range("F2").End(xlDown).Row
For i = 2 To fin
'Cells(i, 7).Select
'On Error Resume Next
On Error GoTo Errorhandler
If Cells(i, 7).Value = "Etat" Then
Cells(i, 11).Value = 1
ElseIf Cells(i, 7).Value = "NR" Then
Cells(i, 11).Value = 23
ElseIf Cells(i, 7).Value = "AAA" Then
Cells(i, 11).Value = 2
ElseIf Cells(i, 7).Value = "AA+" Then
Cells(i, 11).Value = 3
ElseIf Cells(i, 7).Value = "AA" Then
Cells(i, 11).Value = 4
ElseIf Cells(i, 7).Value = "AA-" Then
Cells(i, 11).Value = 5
ElseIf Cells(i, 7).Value = "A+" Then
Cells(i, 11).Value = 6
ElseIf Cells(i, 7).Value = "A" Then
Cells(i, 11).Value = 7
ElseIf Cells(i, 7).Value = "A-" Then
Cells(i, 11).Value = 8
ElseIf Cells(i, 7).Value = "BBB+" Then
Cells(i, 11).Value = 9
ElseIf Cells(i, 7).Value = "BBB" Then
Cells(i, 11).Value = 10
ElseIf Cells(i, 7).Value = "BBB-" Then
Cells(i, 11).Value = 11
ElseIf Cells(i, 7).Value = "BB+" Then
Cells(i, 11).Value = 12
ElseIf Cells(i, 7).Value = "BB" Then
Cells(i, 11).Value = 13
ElseIf Cells(i, 7).Value = "BB-" Then
Cells(i, 11).Value = 14
ElseIf Cells(i, 7).Value = "B+" Then
Cells(i, 11).Value = 17
ElseIf Cells(i, 7).Value = "B" Then
Cells(i, 11).Value = 18
ElseIf Cells(i, 7).Value = "B-" Then
Cells(i, 11).Value = 19
ElseIf Cells(i, 7).Value = "CCC" Then
Cells(i, 11).Value = 20
ElseIf Cells(i, 7).Value = "CC" Then
Cells(i, 11).Value = 21
ElseIf Cells(i, 7).Value = "D" Then
Cells(i, 11).Value = 22

'ElseIf IsNumeric(Cells(i, 7).Value) Then Cells(i, 11).Value = ""
End If
Next i

Exit Sub

Errorhandler:
'fin = Range("F2").End(xlDown).Row
'For i = 2 To fin
If IsError(Cells(i, 7).Value) = True Then Cells(i, 11).Value = ""
'ActiveCell.Offset(0, 4).Value = "toto"
'Next i

Resume Next


End Sub

Je voudrai en fait que chaque fois qu'il y une erreur de ce type, que la macro n'en tienne pas compte et renvoie rien ds la collonne 11.

QQun sait comment faire?
 
J

jaccard

Guest
Hello, essaye voir :

Sub Chiffre1()
Dim vntValeur, vntNote As Variant
Dim intIndex As Integer

vntValeur = Array("Etat", "NR", "AAA", "AA+", "AA", "AA-", "A+", "A", "A-", "BBB+", "BBB", "BBB-", "BB+", "BB", "BB-", "B+", "B", "B-", "CCC", "CC", "D")
vntNote = Array(1, 23, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 22)

fin = Range("F2").End(xlDown).Row
For i = 2 To fin
If IsError(Cells(i, 7).Value) = True Then
Cells(i, 11).ClearContents
Else
For intIndex = 0 To UBound(vntValeur)
If vntValeur(intIndex) = Cells(i, 7).Value Then
Cells(i, 11).Value = vntNote(intIndex)
Exit For
End If
Next intIndex
End If
Next i
End Sub


dom ;-)
 

Statistiques des forums

Discussions
314 095
Messages
2 105 817
Membres
109 436
dernier inscrit
alex.972