Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 12/09/2011, 11h49   #1
Membre à l'essai
 
Inscription : avril 2011
Messages : 67
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 67
Points : 21
Points : 21
Par défaut problème d'arrondi dans une marco

bonjour,

Dans le code ci-dessous je converti ma valeur en texte pour supprimer les chiffres après la virgulle et ne garder que les entiers.

Le soucis est que excel arrondi à l'entier supérieur.

Comment faire pour garde l'entier uniquement sans arrondi supérieur?

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Private Sub calculpacks()
 
Dim i As Long
 
'boucle sur la colonne A
For i = 2 To Range("A65536").End(xlUp).Row
 
    If Range("A" & i).Value <> "" Then
    Range("D" & i).Select
    ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-1]"
    Selection.NumberFormat = "0"
    Range("D" & i) = Range("D" & i).Text
    Range("E" & i).Select
    ActiveCell.FormulaR1C1 = "=RC[-3]-(RC[-2]*RC[-1])"
    Selection.NumberFormat = "0"
    End If
 
Next i
 
End Sub
gigalia est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/09/2011, 11h53   #2
Membre actif
 
Inscription : novembre 2008
Messages : 188
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 188
Points : 194
Points : 194
Bonjour,

Citation:
Envoyé par gigalia Voir le message
Comment faire pour garde l'entier uniquement sans arrondi supérieur?
Sclarckone est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/09/2011, 12h21   #3
Membre à l'essai
 
Inscription : avril 2011
Messages : 67
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 67
Points : 21
Points : 21
Bonjour,

J'ai vu dans un autre post les différentes possibilité dont la tienne ("floor").

J'ai pris pour ma part "fix".

Voila le code

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Private Sub calculpacks()
 
Dim i As Long
 
'boucle sur la colonne A
For i = 2 To Range("A65536").End(xlUp).Row
 
    If Range("A" & i).Value <> "" Then
    If Range("C" & i).Value <> "" Then
    Range("D" & i).Select
    ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-1]"
    Selection.NumberFormat = "0.0"
    Range("D" & i) = Fix(Range("D" & i).Value)
    Range("E" & i).Select
    ActiveCell.FormulaR1C1 = "=RC[-3]-(RC[-2]*RC[-1])"
    Selection.NumberFormat = "0"
    End If
    End If
 
Next i
 
End Sub
gigalia est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/09/2011, 12h34   #4
Expert Confirmé Sénior
 
Avatar de mercatog
 
Inscription : juillet 2008
Messages : 5 848
Détails du profil
Informations forums :
Inscription : juillet 2008
Messages : 5 848
Points : 13 907
Points : 13 907
Bonjour
C'est la fonction ENT d'Excel

Une proposition pour ton code (à adapter)
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Private Sub calculpacks()
Dim LastLig As Long, i As Long
 
Application.ScreenUpdating = False
With Worksheets("Feuil1")                        'A adapter
    LastLig = .Cells(.Rows.Count, "A").End(xlUp).Row
    With .Range("D2:D" & LastLig)
        .FormulaR1C1 = "=IF(AND(RC[-3]<>"""",RC[-1]<>0),INT(RC[-2]/RC[-1]),"""")"
        .Value = .Value
    End With
    With .Range("E2:E" & LastLig)
        .FormulaR1C1 = "=RC[-3]-(RC[-2]*RC[-1])"
        .Value = .Value
    End With
End With
End Sub
__________________
Cordialement.
mercatog est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 23h53.


 
 
 
 
Partenaires

Hébergement Web