VBA: Procedure évènementiel

Hellboy

XLDnaute Accro
Bonjour

Dans une procédure qui réagit si une valeur de cellule de la feuille active change(en fonction d'un choix d'utilisateur), je tente d'aller chercher d'autres valeurs d'une autre feuille pour modifier des cellules de la feuille active. Mais le code ne finit pas de s'exécuter. À la ligne ou la valuer doit être mise ds la cellule de la feuille active, le code arrête là et rien ne se passe.

Exemple:
Sub FeuilleA_Change()

feuilleA.cells(1,2).value = Feuille2.cells(1,2)

ed sub

Est-ce quelqun sait pourquoi, ou sait comment éviter ce problème ?

Merci


Private Sub Worksheet_Change(ByVal Target As Range)
Dim bytCol As Byte, bytColRef As Byte, bytRow As Byte
Dim vrtCell As Variant
Dim intTarget As Integer

'Application.EnableEvents = False

If Target.Row = 8 Then
intTarget = Cells(7, 3).Value
'Call Test(intTarget)
bytColRef = 5
With ThisWorkbook.Worksheets("Ref")
For bytRow = 20 To 24 Step 2
Cells(bytRow, 2) = .Cells(2 + intTarget, bytColRef)
Cells(bytRow, 3) = .Cells(2 + intTarget, bytColRef + 1)
bytColRef = bytColRef + 2
Next bytRow
End With
Else

With Target
Select Case .Row
Case 20
bytCol = 5
Case 22
bytCol = 7
Case 24
bytCol = 9
End Select
On Error Resume Next
If Err Then
Err.Clear
On Error GoTo 0
Exit Sub
End If
If .Column = 2 Then
ThisWorkbook.Worksheets("Ref").Cells(Cells(2, 1) + 2, bytCol).Value = Val(.Value)
Els e eIf .Column = 3 Then
ThisWorkbook.Worksheets("Ref").Cells(Cells(2, 1) + 2, bytCol + 1).Value = Val(.Value)
End If
End With

e]For Each vrtCell In Range("B20:C24,B29:C31")
With vrtCell
Select Case .Value
Case 0
.NumberFormat = "0.0"
Case Is <= -1000, Is >= 1000, Is <= 0.001, Is <= -0.001
.NumberFormat = "###.0##E+##"
Case Else
.NumberFormat = "###.0##"
End Select
End With
If Err Then
Err.Clear
On Error GoTo 0
Exit For
End If
Next vrtCell
End If
'Application.EnableEvents = True
 
Dernière édition:

dg62

XLDnaute Barbatruc
Re : VBA: Procedure évènementiel

Salut HellBoy


je viens de tracer ton prog sur ma config et tout ce passe normalement

les données de la feuille "ref" se recopient dans la feuille active et un format spécifique est appliqué.

Tu devrais joindre ton fichier.


ma config : excel 2003 sous xp pro
 

Statistiques des forums

Discussions
312 287
Messages
2 086 827
Membres
103 397
dernier inscrit
Kilement