Onderstaande VBA code is gemaakt voor een query. Deze VBA berekend het gemiddelde van een aantal getallen uit de gegevens-kolom.
Is het mogelijk om deze VBA op de tabel toe te passen, waar de gegevens dus oorspronkelijk vandaan komen?
Nu heb ik speciaal een query aangemaakt, om de berekening te kunnen maken.
Option Compare Database
Public Function op_plant(a) As String
g1 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 1, 2))
g2 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 4, 2))
g3 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 7, 2))
g4 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 10, 2))
g5 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 13, 2))
g6 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 16, 2))
g7 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 19, 2))
g8 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 22, 2))
g9 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 25, 2))
Select Case Len(a)
Case Is < 2
op_plant = 0
Case Is < 3
op_plant = CStr(g1)
Case Is < 6
op_plant = CStr(Int((g1 + g2) / 2))
Case Is < 9
op_plant = CStr(Int((g1 + g2 + g3) / 3))
Case Is < 12
op_plant = CStr(Int((g1 + g2 + g3 + g4) / 4))
Case Is < 15
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5) / 5))
Case Is < 18
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6) / 6))
Case Is < 21
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6 + g7) / 7))
Case Is < 24
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6 + g7 + g8) / 8))
Case Else
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6 + g7 + g8 + g9) / 9))
End Select
If Len(op_plant) = 1 Then
op_plant = "0" & op_plant
End If
End Function
Ik hoop dat iemand me verder kan helpen!
Is het mogelijk om deze VBA op de tabel toe te passen, waar de gegevens dus oorspronkelijk vandaan komen?
Nu heb ik speciaal een query aangemaakt, om de berekening te kunnen maken.
Option Compare Database
Public Function op_plant(a) As String
g1 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 1, 2))
g2 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 4, 2))
g3 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 7, 2))
g4 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 10, 2))
g5 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 13, 2))
g6 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 16, 2))
g7 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 19, 2))
g8 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 22, 2))
g9 = Val(Mid$(a & "-00-00-00-00-00-00-00-00-00", 25, 2))
Select Case Len(a)
Case Is < 2
op_plant = 0
Case Is < 3
op_plant = CStr(g1)
Case Is < 6
op_plant = CStr(Int((g1 + g2) / 2))
Case Is < 9
op_plant = CStr(Int((g1 + g2 + g3) / 3))
Case Is < 12
op_plant = CStr(Int((g1 + g2 + g3 + g4) / 4))
Case Is < 15
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5) / 5))
Case Is < 18
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6) / 6))
Case Is < 21
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6 + g7) / 7))
Case Is < 24
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6 + g7 + g8) / 8))
Case Else
op_plant = CStr(Int((g1 + g2 + g3 + g4 + g5 + g6 + g7 + g8 + g9) / 9))
End Select
If Len(op_plant) = 1 Then
op_plant = "0" & op_plant
End If
End Function
Ik hoop dat iemand me verder kan helpen!