D
DG
I can't see what is wrong with this code
In the Function MaxOfArray I get a type mismatch on the line "For i = 1 To
UBound(TheArray). I think it has something to do with Set OrderDateArray =
Sheets("Sheet2").Range("A2", Range("A65536").End(xlUp)) , which has only 36
rows.
Even if I put k = UBound(OrderDateArray) in the main sub I get the error. I
know this must be something simple that I can't see.
Sub Forcast_Prod()
Dim OrderDateArray As Variant
Set OrderDateArray = Sheets("Sheet2").Range("A2",
Range("A65536").End(xlUp))
Max_Date = MaxOfArray(OrderDateArray)
End Sub
Function MaxOfArray(ByRef TheArray As Variant) As Integer
' This function gives the max value of an integer array without sorting
the array
Dim i As Integer
Dim MaxIntIndex As Integer
MaxIntIndex = 0
For i = 1 To UBound(TheArray)
If TheArray(i) > TheArray(MaxIntIndex) Then
MaxIntIndex = i
End If
Next
'index of max value is MaxValOfArray
MaxOfArray = TheArray(MaxIntIndex)
End Function
In the Function MaxOfArray I get a type mismatch on the line "For i = 1 To
UBound(TheArray). I think it has something to do with Set OrderDateArray =
Sheets("Sheet2").Range("A2", Range("A65536").End(xlUp)) , which has only 36
rows.
Even if I put k = UBound(OrderDateArray) in the main sub I get the error. I
know this must be something simple that I can't see.
Sub Forcast_Prod()
Dim OrderDateArray As Variant
Set OrderDateArray = Sheets("Sheet2").Range("A2",
Range("A65536").End(xlUp))
Max_Date = MaxOfArray(OrderDateArray)
End Sub
Function MaxOfArray(ByRef TheArray As Variant) As Integer
' This function gives the max value of an integer array without sorting
the array
Dim i As Integer
Dim MaxIntIndex As Integer
MaxIntIndex = 0
For i = 1 To UBound(TheArray)
If TheArray(i) > TheArray(MaxIntIndex) Then
MaxIntIndex = i
End If
Next
'index of max value is MaxValOfArray
MaxOfArray = TheArray(MaxIntIndex)
End Function