Partager via

Chiffres après la virgules non pris en compte

Anonyme
2024-07-29T14:37:38+00:00

Bonjour

Le code ci-dessous me donne un résultat entier alors qu'en ["i4:j16] j'ai des chiffres derrières la virgule qui ne sont pas pris en compte.

Merci

Option Explicit

Dim i As Long

Dim sTemp As String

Dim a

Dim bTest As Boolean

Dim Test As Boolean

Dim Ctr As Single


Private Sub ListBox1_Change()

Dim Ctr As Long

If Test Then

Exit Sub

End If

Ctr = 0

If bTest Then

Exit Sub

End If

sTemp = ""

For i = 0 To Me.ListBox1.ListCount - 1

If Me.ListBox1.Selected(i) Then

sTemp = sTemp & Me.ListBox1.List(i) & "-" 

Ctr = Ctr + Application.VLookup(Me.ListBox1.List(i), Sheets("References").Range("i4:j16"), 2, False) 

End If 

Next

If sTemp <> "" Then

sTemp = VBA.Left(sTemp, VBA.Len(sTemp) - 1)

ActiveCell = sTemp

ActiveCell.Offset(0, 1) = Ctr

Else

ActiveCell = ""

ActiveCell.Offset(0, 1) = 0

End If

End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim Count As Range

Dim Ligne

If ActiveCell.Column = 8 Then

Application.EnableEvents = False

Test = 1

With Me.ListBox1 'deselect

For i = 0 To .ListCount - 1

If .Selected(i) = True Then .Selected(i) = False

Next i

End With

Application.EnableEvents = True

Test = 0

Ligne = ActiveCell.Row

If Cells(ActiveCell.Row, 2) = "" Then

Me.ListBox1.Visible = False

Exit Sub

End If

With Me.ListBox1

.MultiSelect = fmMultiSelectMulti

.ListStyle = fmListStyleOption 'case à cocher

.Height = 250

.Width = 200

.Top = ActiveCell.Top

.Left = ActiveCell.Offset(0, 3).Left

.Visible = True

End With

On Error Resume Next

i = Application.WorksheetFunction.Match(Cells(ActiveCell.Row, 2), Worksheets("References").Range("PlusValues"), 0) - 1

Me.ListBox1.List = Worksheets("References").Range(Worksheets("Reference").Range("i3").Offset(1, i), _

Worksheets("Reference").Range("i3").Offset(0, i).End(xlDown)).Value 

On Error GoTo 0

a = VBA.Split(ActiveCell, "-")

If UBound(a) >= 0 Then

For i = 0 To Me.ListBox1.ListCount - 1 

  If Not IsError(Application.Match(Me.ListBox1.List(i), a, 0)) Then 

    bTest = True 

    Me.ListBox1.Selected(i) = True 

    bTest = False 

  End If   

Next 

End If

Else

Me.ListBox1.Visible = False

End If

End Sub

Microsoft 365 et Office | Excel | Autres | Windows

Question verrouillée. Cette question a été migrée à partir de la Communauté Support Microsoft. Vous pouvez voter pour indiquer si elle est utile, mais vous ne pouvez pas ajouter de commentaires ou de réponses ni suivre la question.

0 commentaires Aucun commentaire

Réponse acceptée par l’auteur de la question

  1. DanielCo 107.7K Points de réputation
    2024-07-29T15:21:45+00:00

    Bonjour,

    Quelle variable ou cellule donne un entier ? Si c'est "Ctr", c'est normal, puisqu'elle est de type "Long".

    Daniel

    Cette réponse a-t-elle été utile ?

    1 personne a trouvé cette réponse utile.
    0 commentaires Aucun commentaire

1 réponse supplémentaire

  1. Anonyme
    2024-07-29T15:45:54+00:00

    Bonjour Daniel,

    Effectivement et je l'avais déclarée à 2 endroits différemment

    Je te remercie

    Thierry

    Cette réponse a-t-elle été utile ?

    0 commentaires Aucun commentaire