Function
CALCVERSAND(length, hight, width, weight)
Dim
side1, side2, side3, i, counter
As
Integer
Dim
X
As
Variant
Dim
categorys(), types()
As
String
Dim
Debug1, Debug2, Debug3
As
Variant
X = Worksheets(
"Versands Kosten"
).Range(
"A14:I54"
)
counter = 0
ReDim
categorys(0)
categorys(0) =
CStr
(X(1, 1))
For
i = LBound(X, 1)
To
UBound(X, 1)
If
CStr
(X(i, 1)) <> categorys(counter)
Then
ReDim
Preserve
categorys(counter + 1)
categorys(counter + 1) = X(i, 1)
counter = counter + 1
End
If
Next
counter = 0
i = 0
ReDim
types(0)
types(0) =
CStr
(X(1, 2))
For
i = LBound(X, 1)
To
UBound(X, 1)
If
CStr
(X(i, 2)) <> types(counter)
Then
ReDim
Preserve
types(counter + 1)
types(counter + 1) = X(i, 2)
counter = counter + 1
End
If
Next
side1 = Application.Max(length, hight, width)
side2 = Application.Median(length, hight, width)
side3 = Application.Min(length, hight, width)
i = 0
For
i = LBound(X, 1)
To
UBound(X, 1)
If
side1 <= X(i, 3)
And
side2 <= X(i, 4)
And
side3 <= X(i, 5)
And
weight <= (X(i, 6) + X(i, 7))
Then
Debug1 = X(i, 3)
Debug2 = X(i, 4)
Debug3 = X(i, 7)
Exit
For
End
If
Next
CALCVERSAND = X(i, 2)
End
Function