2017-08-15 48 views
1

我想添加具有这样一个日期(strDateForm = strDate)和strFunction =“1”的列中的所有小时,但我的功能只需要最后一个列中的数据而不是添加所有相应的数据。 有人可以帮助我。取而代之的添加所有在一个列vba excel的小时为每个,如果

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

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 
+0

试着让你的另外一共有发生的循环内,让你的总时间可以继续累加,而不是发生一个细胞。 – Cyril

回答

2

你应该做

heureTotale = heureTotale + CSng(srcRow.Range.Cells(1, 13).Value) 
相关问题