Heureux d'avoir pu aider. On peut simplifier davantage et ne conserver que Dim Rg As Range
Set Rg = Intersect(Target, Range("H2:H10")) If Not Rg Is Nothing Then For Each c In Rg Application.EnableEvents = False If Not IsNumeric(c) Then MsgBox c.Value & " n'est pas un nombre" Else c.Value = Int(c) * 100 + Format(c - Int(c), ".00") * 100 End If Application.EnableEvents = True Next End If Set Rg = Nothing
"Loïc" wrote in message news:c752ln$duj$
Bonjour Loïc. C'est une piste intéressante que de vouloir récupérer les décimales. Voici une façon de récupérer les 2 premières décimales par la formule c - Int(c) : Gérard
Private Sub Worksheet_Change(ByVal Target As Range) Dim Rg As Range
Set Rg = Intersect(Target, Range("H2:H10")) If Not Rg Is Nothing Then For Each c In Rg Application.EnableEvents = False If Not IsNumeric(c) Then MsgBox c.Value & " n'est pas un nombre" Else If c = Int(c) Then 'Vérifie si c'est un nombre entier c.Value = c * 100 'si oui ajouter 00 Else 'si non seules les 2 premières décimales sont conservées c.Value = Int(c) * 100 + Format(c - Int(c), ".00") * 100 End If End If Application.EnableEvents = True Next End If Set Rg = Nothing End Sub
Merci infiniment cela convient parfaitement !!
Heureux d'avoir pu aider.
On peut simplifier davantage et ne conserver que
Dim Rg As Range
Set Rg = Intersect(Target, Range("H2:H10"))
If Not Rg Is Nothing Then
For Each c In Rg
Application.EnableEvents = False
If Not IsNumeric(c) Then
MsgBox c.Value & " n'est pas un nombre"
Else
c.Value = Int(c) * 100 + Format(c - Int(c), ".00") * 100
End If
Application.EnableEvents = True
Next
End If
Set Rg = Nothing
"Loïc" <ath25_marreduspam@hotmail.com> wrote in message
news:c752ln$duj$1@news-reader4.wanadoo.fr...
Bonjour Loïc.
C'est une piste intéressante que de vouloir récupérer les décimales.
Voici une façon de récupérer les 2 premières décimales
par la formule c - Int(c) :
Gérard
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rg As Range
Set Rg = Intersect(Target, Range("H2:H10"))
If Not Rg Is Nothing Then
For Each c In Rg
Application.EnableEvents = False
If Not IsNumeric(c) Then
MsgBox c.Value & " n'est pas un nombre"
Else
If c = Int(c) Then 'Vérifie si c'est un nombre entier
c.Value = c * 100 'si oui ajouter 00
Else
'si non seules les 2 premières décimales sont conservées
c.Value = Int(c) * 100 + Format(c - Int(c), ".00") * 100
End If
End If
Application.EnableEvents = True
Next
End If
Set Rg = Nothing
End Sub
Heureux d'avoir pu aider. On peut simplifier davantage et ne conserver que Dim Rg As Range
Set Rg = Intersect(Target, Range("H2:H10")) If Not Rg Is Nothing Then For Each c In Rg Application.EnableEvents = False If Not IsNumeric(c) Then MsgBox c.Value & " n'est pas un nombre" Else c.Value = Int(c) * 100 + Format(c - Int(c), ".00") * 100 End If Application.EnableEvents = True Next End If Set Rg = Nothing
"Loïc" wrote in message news:c752ln$duj$
Bonjour Loïc. C'est une piste intéressante que de vouloir récupérer les décimales. Voici une façon de récupérer les 2 premières décimales par la formule c - Int(c) : Gérard
Private Sub Worksheet_Change(ByVal Target As Range) Dim Rg As Range
Set Rg = Intersect(Target, Range("H2:H10")) If Not Rg Is Nothing Then For Each c In Rg Application.EnableEvents = False If Not IsNumeric(c) Then MsgBox c.Value & " n'est pas un nombre" Else If c = Int(c) Then 'Vérifie si c'est un nombre entier c.Value = c * 100 'si oui ajouter 00 Else 'si non seules les 2 premières décimales sont conservées c.Value = Int(c) * 100 + Format(c - Int(c), ".00") * 100 End If End If Application.EnableEvents = True Next End If Set Rg = Nothing End Sub