Ik heb het onderstaande stukje VBA in een database zitten. Deze telt de getallen van 1 kolom op, en zet in de kolom erna het gemiddelde ervan.
Om te kunnen sorteren zouden 1-cijferige getallen weergegeven moeten worden als 02, 03,04 e.d.
Dit gebeurt nu niet, er staat nu gewoon 2, 3 en 4.
Wie weet hoe ik dit aan kan passen?
Groetjes,
Cindy
Function potplant(a)
g1 = Val(Mid$(a & "-00-00-00-00-00-00", 1, 2))
g2 = Val(Mid$(a & "-00-00-00-00-00-00", 4, 2))
g3 = Val(Mid$(a & "-00-00-00-00-00-00", 7, 2))
g4 = Val(Mid$(a & "-00-00-00-00-00-00", 10, 2))
g5 = Val(Mid$(a & "-00-00-00-00-00-00", 13, 2))
g6 = Val(Mid$(a & "-00-00-00-00-00-00", 16, 2))
If Len(a) < 2 Then
potplant = 0
Else
If Len(a) < 3 Then
potplant = g1
Else
If Len(a) < 6 Then
potplant = Int((g1 + g2) / 2)
Else
If Len(a) < 9 Then
potplant = Int((g1 + g2 + g3) / 3)
Else
If Len(a) < 12 Then
potplant = Int((g1 + g2 + g3 + g4) / 4)
Else
If Len(a) < 15 Then
potplant = Int((g1 + g2 + g3 + g4 + g5) / 5)
Else
potplant = Int((g1 + g2 + g3 + g4 + g5 + g6) / 6)
End If
End If
End If
End If
End If
End If
End Function
Om te kunnen sorteren zouden 1-cijferige getallen weergegeven moeten worden als 02, 03,04 e.d.
Dit gebeurt nu niet, er staat nu gewoon 2, 3 en 4.
Wie weet hoe ik dit aan kan passen?
Groetjes,
Cindy
Function potplant(a)
g1 = Val(Mid$(a & "-00-00-00-00-00-00", 1, 2))
g2 = Val(Mid$(a & "-00-00-00-00-00-00", 4, 2))
g3 = Val(Mid$(a & "-00-00-00-00-00-00", 7, 2))
g4 = Val(Mid$(a & "-00-00-00-00-00-00", 10, 2))
g5 = Val(Mid$(a & "-00-00-00-00-00-00", 13, 2))
g6 = Val(Mid$(a & "-00-00-00-00-00-00", 16, 2))
If Len(a) < 2 Then
potplant = 0
Else
If Len(a) < 3 Then
potplant = g1
Else
If Len(a) < 6 Then
potplant = Int((g1 + g2) / 2)
Else
If Len(a) < 9 Then
potplant = Int((g1 + g2 + g3) / 3)
Else
If Len(a) < 12 Then
potplant = Int((g1 + g2 + g3 + g4) / 4)
Else
If Len(a) < 15 Then
potplant = Int((g1 + g2 + g3 + g4 + g5) / 5)
Else
potplant = Int((g1 + g2 + g3 + g4 + g5 + g6) / 6)
End If
End If
End If
End If
End If
End If
End Function