Dans ce code, je veux obtenir par heure la somme des PC choisis Donc, mon feuille d'excellence a de nombreuses lignes, j'ai déjà un code, mais cela ne subi pas assez vite, dans la colonne S est remplie de longtimevalues DD: mm: yyy & hh: mm: ss dans la colonne P est rempli avec les PC qui sont cueillies sur Ce temps
AJ2 jusqu'à AJ10 est une valeur d'heure 5, 6, 7 et ainsi de suite sur AJ10 = 13 AK2 jusqu'à ce que AK10 soient les PC cueillis dans cette heure p>
même est AL2 jusqu'à AL10 est la valeur de l'heure 14, 15, 16 et ainsi de suite AL10 = 22 AM2 jusqu'à AM10 sont les PC cueillis dans cette heure p>
aussi il doit également résumer et vérifier l'heure PCS uniquement les cellules visibles qui ont des valeurs de valeur P>
le code pour le moment que j'ai Cette solution VBA ou Excell P>
J'ai VBA écrit pour le moment, mais comme je l'ai dit pas assez vite, il faut un long chemin pour sommer tout le code P>
Private Sub CheckBox6_Click()
If CheckBox6.Value = True Then
Dim lijnen As String
lijnen = "an15:an" & Range("s15").End(xlDown).Row
Application.ScreenUpdating = False
For Each cell In Range(lijnen).SpecialCells(xlCellTypeVisible)
If cell.Value <> "" Then
If Format(cell.Value, "hh") = Format(Range("aj2").Value, "hh") Then
Range("ak2").Value = Range("ak2").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj3").Value, "hh") Then
Range("ak3").Value = Range("ak3").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj4").Value, "hh") Then
Range("ak4").Value = Range("ak4").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj5").Value, "hh") Then
Range("ak5").Value = Range("ak5").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj6").Value, "hh") Then
Range("ak6").Value = Range("ak6").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj7").Value, "hh") Then
Range("ak7").Value = Range("ak7").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj8").Value, "hh") Then
Range("ak8").Value = Range("ak8").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj9").Value, "hh") Then
Range("ak9").Value = Range("ak9").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("aj10").Value, "hh") Then
Range("ak10").Value = Range("ak10").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al2").Value, "hh") Then
Range("am2").Value = Range("am2").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al3").Value, "hh") Then
Range("am3").Value = Range("am3").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al4").Value, "hh") Then
Range("am4").Value = Range("am4").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al5").Value, "hh") Then
Range("am5").Value = Range("am5").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al6").Value, "hh") Then
Range("am6").Value = Range("am6").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al7").Value, "hh") Then
Range("am7").Value = Range("am7").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al8").Value, "hh") Then
Range("am8").Value = Range("am8").Value + Range("p" & cell.Row).Value
Else
If Format(cell.Value, "hh") = Format(Range("al9").Value, "hh") Then
Range("am9").Value = Range("am9").Value + Range("p" & cell.Row).Value
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next cell
End If
Application.ScreenUpdating = True
End Sub
3 Réponses :
Éteindre les calculs Excel améliore généralement les performances. Le code suivant inclut que, avec des instructions nettoyées si code>. If CheckBox6.Value = True Then
Dim lijnen As String
lijnen = "an15:an" & Range("s15").End(xlDown).Row
Dim calc As XlCalculation: calc = Application.Calculation 'captures your current setting
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each cell In Range(lijnen).SpecialCells(xlCellTypeVisible)
If cell.Value <> "" Then
If Format(cell.Value, "hh") = Format(Range("aj2").Value, "hh") Then
Range("ak2").Value = Range("ak2").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj3").Value, "hh") Then
Range("ak3").Value = Range("ak3").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj4").Value, "hh") Then
Range("ak4").Value = Range("ak4").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj5").Value, "hh") Then
Range("ak5").Value = Range("ak5").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj6").Value, "hh") Then
Range("ak6").Value = Range("ak6").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj7").Value, "hh") Then
Range("ak7").Value = Range("ak7").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj8").Value, "hh") Then
Range("ak8").Value = Range("ak8").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj9").Value, "hh") Then
Range("ak9").Value = Range("ak9").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("aj10").Value, "hh") Then
Range("ak10").Value = Range("ak10").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al2").Value, "hh") Then
Range("am2").Value = Range("am2").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al3").Value, "hh") Then
Range("am3").Value = Range("am3").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al4").Value, "hh") Then
Range("am4").Value = Range("am4").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al5").Value, "hh") Then
Range("am5").Value = Range("am5").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al6").Value, "hh") Then
Range("am6").Value = Range("am6").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al7").Value, "hh") Then
Range("am7").Value = Range("am7").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al8").Value, "hh") Then
Range("am8").Value = Range("am8").Value + Range("p" & cell.Row).Value
ElseIf Format(cell.Value, "hh") = Format(Range("al9").Value, "hh") Then
Range("am9").Value = Range("am9").Value + Range("p" & cell.Row).Value
End If
End If
Next cell
Application.ScreenUpdating = True
Application.Calculation = calc 'resets this back to whatever it previously was
End If
End Sub
Cela peut aider à la question de la vitesse. J'ai remarqué que vous utilisez Cell.Value beaucoup et cela élimine cela. Il nettoie également votre code un peu. Cependant, il ne fait aucune erreur d'erreur si la cellule est vide.
Option Explicit
Private Sub CheckBox6_Click()
Dim strValue As String
Dim lngRow As Long
Dim lngPValue As Long
Dim strPValue As String
If CheckBox6.Value = True Then
Dim lijnen As String
lijnen = "an15:an" & Range("s15").End(xlDown).Row
Application.ScreenUpdating = False
For Each cell In Range(lijnen).SpecialCells(xlCellTypeVisible)
strValue = Trim(cell.value)
If strValue <> "" Then
strValue = Format(cell.Value, "hh")
lngRow = cell.Row
strPValue = Trim(Range("p" & lngRow).Value)
lngPValue = CLng(strPValue)
If strValue = Format(Range("aj2").Value, "hh") Then
Range("ak2").Value = Range("ak2").Value + lngPValue
ElseIf strValue = Format(Range("aj3").Value, "hh") Then
Range("ak3").Value = Range("ak3").Value + lngPValue
ElseIf strValue = Format(Range("aj4").Value, "hh") Then
Range("ak4").Value = Range("ak4").Value + lngPValue
ElseIf strValue = Format(Range("aj5").Value, "hh") Then
Range("ak5").Value = Range("ak5").Value + lngPValue
ElseIf strValue = Format(Range("aj6").Value, "hh") Then
Range("ak6").Value = Range("ak6").Value + lngPValue
ElseIf strValue = Format(Range("aj7").Value, "hh") Then
Range("ak7").Value = Range("ak7").Value + lngPValue
ElseIf strValue = Format(Range("aj8").Value, "hh") Then
Range("ak8").Value = Range("ak8").Value + lngPValue
ElseIf strValue = Format(Range("aj9").Value, "hh") Then
Range("ak9").Value = Range("ak9").Value + lngPValue
ElseIf strValue = Format(Range("aj10").Value, "hh") Then
Range("ak10").Value = Range("ak10").Value + lngPValue
ElseIf strValue = Format(Range("al2").Value, "hh") Then
Range("am2").Value = Range("am2").Value + lngPValue
ElseIf strValue = Format(Range("al3").Value, "hh") Then
Range("am3").Value = Range("am3").Value + lngPValue
ElseIf strValue = Format(Range("al4").Value, "hh") Then
Range("am4").Value = Range("am4").Value + lngPValue
ElseIf strValue = Format(Range("al5").Value, "hh") Then
Range("am5").Value = Range("am5").Value + lngPValue
ElseIf strValue = Format(Range("al6").Value, "hh") Then
Range("am6").Value = Range("am6").Value + lngPValue
ElseIf strValue = Format(Range("al7").Value, "hh") Then
Range("am7").Value = Range("am7").Value + lngPValue
ElseIf strValue = Format(Range("al8").Value, "hh") Then
Range("am8").Value = Range("am8").Value + lngPValue
ElseIf strValue = Format(Range("al9").Value, "hh") Then
Range("am9").Value = Range("am9").Value + lngPValue
End If
End If
Next cell
End If
Application.ScreenUpdating = True
End Sub
Je vais essayer le code, a aussi fait celui ci-dessus grand que vous voulez me répondre THX
Vous pouvez également insérer ce que @pgCoderider a dit pour son code dans ce que j'ai mis. Il vous aidera également à accélérer le code.
Généralement, vous souhaitez éviter la boucle, mais une boucle à travers des tableaux si vous devez faire boucle. Vos spécialités (XLCelltypeVisible) posent un problème car il peut y avoir des zones non contiguës dans la plage, mais elles peuvent être traitées.
vous avez écrit gamme.Value2 (sans informations régionales de date / heure ou de devise) est marginalement plus rapide que la plage.value. La collecte numérique et la comparaison sont plus rapides que la collecte et la comparaison des chaînes. P> Ceci semble être écrit comme un sous privé dans une feuille de code privée de la feuille de calcul défini explicitement la référence de la feuille de calcul des parents doit être inutile. P> < Pré> xxx pré> p> si SOPEIF aseflaniform ... fin si code> comparaisons . J'ai changé cela dans une comparaison de match de la feuille de travail. P>
Vous devez utiliser
elseif code> plutôt que tant de singlesi code> déclarations. Cela peut ne pas accélérer votre code beaucoup, mais il semblera plus élégant.