format conditionnel et VBA

  • Initiateur de la discussion igor
  • Date de début
I

igor

Guest
Bonjour,
Je rencontre un probléme de formatage conditionnel sous VBA .pouvez vous m'aider?

Voir fichier joint

MERCI

igor [file name=Test_20060518121509.zip size=9454]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/Test_20060518121509.zip[/file]
 

Pièces jointes

  • Test_20060518121509.zip
    9.2 KB · Affichages: 11

Hellboy

XLDnaute Accro
Bonjour igor

Je me demande pourquoi du met une boucle dans ton code ? Je ne vois pas comment elle sert !
Pour ce qui est de l'arrondissement, la façon de t'en sortir est d'utiliser la fonction de Excel. Soit:

val = Application.WorksheetFunction.Round(.Value, 3)

Voici ma suggestion:
Sub worksheet_change(ByVal Target As Range)

       
Dim val, val2, val3 As Variant
       
With Target
                val2 = Sheets('Objectifs').Cells(.Row, .Column - 2).Value
                val3 = Sheets('Objectifs + ou - 5%').Cells(.Row, .Column - 2).Value
               
'val = Round(cell.Value, 3)
                val = Application.WorksheetFunction.Round(.Value, 3)
               
If .Value = Empty Then
                        MsgBox 'L'arrondi VBA est : ' & val, vbOKOnly
                        .Interior.ColorIndex = 2
                        .Font.ColorIndex = 1
               
ElseIf .Value >= 0 And val = val2 + 0.001 And val <= val3 + 0.001 - 1E-16 Then
                        MsgBox 'L'arrondi VBA est : ' & val, vbOKOnly
                        .Interior.ColorIndex = 36
                        .Font.ColorIndex = 1
               
Else: MsgBox 'L'arrondi VBA est : ' & val, vbOKOnly
                        .Interior.ColorIndex = 40
                        .Font.ColorIndex = 1
               
End If
       
End With
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
311 720
Messages
2 081 915
Membres
101 837
dernier inscrit
Ugo