添加所有的时间在一个列VBA的Excel与每个和如果

我想添加具有这样一个date(strDateForm = strDate)和strFunction =“1”的列中的所有小时,但我的函数只取得列中的最后一个数据,而不是添加所有相应的数据。 有人能帮助我吗。

Public Sub CalculHeuresTotalChauffeur() Dim tblPagination As ListObject Set tblPagination = Worksheets("Pagination").ListObjects.Item ("tblPagination") Dim heureTotale As Single Dim sommeTotale As Single If StrComp(tbxTempsChauffeur, "") = 0 Then tbxTempsChauffeur = "0" If StrComp(tbxTempsChef, "") = 0 Then tbxTempsChef = "0" If StrComp(tbxTempsDemenageur, "") = 0 Then tbxTempsDemenageur = "0" If StrComp(tbxTempsCoordonnateur, "") = 0 Then tbxTempsCoordonnateur = "0" For Each srcRow In tblPagination.ListRows strDate = srcRow.Range.Cells(1, 3) strDateFormulaire = dtpDate.Value strNoFonction = srcRow.Range.Cells(1, 21) If strDateFormulaire = strDate And strNoFonction = "1" Then heureTotale = CSng(srcRow.Range.Cells(1, 13).Value) End If Next sommeTotale = heureTotale + CSng(tbxTempsChauffeur.Value) tbxHeuresChauffeur.Value = sommeTotale End Sub 

代替

 heureTotale = CSng(srcRow.Range.Cells(1, 13).Value) 

你应该做

 heureTotale = heureTotale + CSng(srcRow.Range.Cells(1, 13).Value)