Function
Lifetime()
Dim
c
As
String
Dim
m
As
String
Dim
y
As
String
Dim
d1
As
String
Dim
d2
As
String
Dim
d1cd
As
Date
Dim
d2cd
As
Date
Dim
d3
As
Integer
c = ActiveCell.Value
If
Len(c) = 9
Then
y = Mid(c, 2, 2)
c = Left(c, 1)
m = Asc(c) - 64
d1 =
"20"
+ y &
"/"
& m &
"/01"
d1d =
CDate
(d1)
d2 = ActiveCell.Offset(, 5).Value
d2d =
CDate
(d2)
d3 = DateDiff(
"m"
, d1d, d2d)
MsgBox (
"Die Lifetime der Pumpe beträgt "
& d3 &
" Monate"
)
ElseIf
Len(c) = 12
Then
y = Mid(c, 3, 2)
m = Left(c, 2)
d1 =
"20"
+ y &
"/"
& m &
"/01"
d1d =
CDate
(d1)
d2 = ActiveCell.Offset(, 5).Value
d2d =
CDate
(d2)
d3 = DateDiff(
"m"
, d1d, d2d)
MsgBox (
"Die Lifetime der Pumpe beträgt "
& d3 &
" Monate"
)
Else
MsgBox (
"Ungültige Seriennummer"
)
End
If
End
Function