Public Function ListAverage(ByRef oLst As MSForms.ListBox) As Double With oLst If .ListCount Then Dim i As Long, j As Long Dim dRet As Double dRet = 0# If .ColumnCount < 2 Then For i = 0 To .ListCount - 1 dRet = dRet + CDbl(.List(i)) Next i ListAverage = dRet / .ListCount Else Dim k As Long k = 0 For i = 0 To .ListCount - 1 For j = 0 To .ColumnCount - 1 If IsNull(.List(i, j)) Then Exit For Else dRet = dRet + CDbl(.List(i, j)) k = k + 1 End If Next j Next i ListAverage = dRet / k End If Else ListAverage = 0# End If End With End Function
Public Function ColumnAverage(ByRef oLst As MSForms.ListBox, ByVal pvargColumn As Integer) As Double ' la colonne indiquée doit exister ! commence à 0 Dim dRet As Double dRet = 0# With oLst If .ListCount Then Dim i As Long, j As Long j = 0 For i = 0 To .ListCount - 1 If IsNull(.List(i, pvargColumn)) Then If j 0 Then j 1 'éviter la division/0 Exit For Else dRet = dRet + CDbl(.List(i, pvargColumn)) j = j + 1 End If Next i dRet = dRet / j End If End With ColumnAverage = dRet End Function
Public Function ColumnAverage(ByRef oLst As MSForms.ListBox, ByVal pvargColumn As Integer) As Double ' la colonne indiquée doit exister ! commence à 0 Dim dRet As Double dRet = 0# With oLst If .ListCount Then Dim i As Long, j As Long j = 0 For i = 0 To .ListCount - 1 If IsNull(.List(i, pvargColumn)) Then If j 0 Then j 1 'éviter la division/0 Exit For Else dRet = dRet + CDbl(Replace(.List(i, pvargColumn), ".", ",")) j = j + 1 End If Next i dRet = dRet / j End If End With ColumnAverage = dRet End Function
Public Function calculerMoyenne(byref lstListBox As ListBox) As Double Dim i As Long Dim lTaille As Long Dim lTotal As Long Let lTaille = lstListBox.ListCount - 1 For i = 0 to lTaille Let lTotal = lTotal + lstListBox.List(i) Next i Let calculerMoyenne = lTotal / (lTaille + 1) End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questiondim Xb as double Xb=CalculerMoyenne(userform_accueil.listBox_Points_Homologues) TxtB_Xb.Text=Round(Xb,3)
dim Xb as double Xb=CalculerMoyenne(userform_accueil.listBox_Points_Homologues) TxtB_Xb.Text=CStr(Round(Xb,3))
Xb=CalculerMoyenne(userform_accueil.listBox_Points_Homologues)
Public Function calculerMoyenne(byref lstListBox As ListBox) As Double Dim i As Long Dim lTaille As Long Dim dTotal As Double Let lTaille = lstListBox.ListCount - 1 For i = 0 to lTaille If (isNumeric(lstListBox.List(i)) Then Let dTotal = dTotal + CDbl(lstListBox.List(i)) End If Next i Let calculerMoyenne = dTotal / (lTaille + 1) End Function
Public Function calculerMoyenne(ByRef lstListBox As Object) As Double Dim i As Long Dim lTaille As Long Dim dTotal As Double Let lTaille = lstListBox.ListCount - 1 For i = 0 To lTaille If (IsNumeric(lstListBox.List(i))) Then Let dTotal = dTotal + CDbl(lstListBox.List(i)) End If Next i Let calculerMoyenne = dTotal / (lTaille + 1) End Function
rivate Sub CommandButton_Ouvrir_Click() Dim Fichier Dim Tbld As Single Fichier = Application.GetOpenFilename("Fichier Texte (*.txt), *.txt") If Fichier = False Then Exit Sub If Fichier Like "*" & ThisWorkbook.Name Then MsgBox "Ouverture non autorisée.": Exit Sub On Error Resume Next Open Fichier For Input As #1 On Error GoTo 0 Dim Ligne As String Dim Valeur As Variant Dim Separateur As String Input #1, Ligne Separateur = InputBox("Entrer le séparateur de données : " & Ligne, "Séparateur") Valeur = Split(Ligne, Separateur) ListBox_Points_Homologues.AddItem (Valeur(0)) ListBox_Points_Homologues.List(0, 1) = Valeur(1) ListBox_Points_Homologues.List(0, 2) = Valeur(2) ListBox_Points_Homologues.List(0, 3) = Valeur(3) ListBox_Points_Homologues.List(0, 4) = Valeur(4) While Not (EOF(1)) Input #1, Ligne Valeur = Split(Ligne, Separateur) ListBox_Points_Homologues.AddItem (Valeur(0)) ListBox_Points_Homologues.List(ListBox_Points_Homologues.ListCount - 1, 1) = Valeur(1) ListBox_Points_Homologues.List(ListBox_Points_Homologues.ListCount - 1, 2) = Valeur(2) ListBox_Points_Homologues.List(ListBox_Points_Homologues.ListCount - 1, 3) = Valeur(3) ListBox_Points_Homologues.List(ListBox_Points_Homologues.ListCount - 1, 4) = Valeur(4) Wend Close #1 End Sub
Public Function CalculerMoyenne(ByRef LstB As MSForms.ListBox) As Double Dim i As Long Dim lTaille As Long Dim dTotal As Double Let lTaille = LstB.ListCount - 1 For i = 0 To lTaille If (IsNumeric(LstB.List(i))) Then dTotal = dTotal + CDbl(LstB.List(i)) End If Next i CalculerMoyenne = dTotal / (lTaille + 1) End Function
Private Sub CmdB_Calculer_Bary_Click() Dim Xb As Double Xb = CalculerMoyenne(UserForm_Accueil.ListBox_Points_Homologues)