I am trying to write a function that takes in a variant array (2-dimensions), then goes through it and changes all dates to longs.
Private Function mlDateHelper(a As Variant)
Dim i, j As Integer
For i = 1 To UBound(a.value, 1)
For j = 1 To UBound(a.value, 2)
If IsDate(a(i, j)) Then
a(i, j) = CLng(a(i, j)) 'This line errors out
End If
Next j
Next i
mlDateHelper = a
End Function
Basically, I'm just iterating through the array on both dimensions, and whenever there's a date I'm trying to reset that date to a long.
When I'm debugging it, I can tell that it correctly computes CLng(a(i, j)), but then it crashes when it's trying to assign that value to a(i, j).
It's giving me an "application-defined or object-defined error". Thoughts? Thanks for your help!
athe array that is being passed?UBound(a.value, 2)then a is probably still a Range and so you need to saya(i, j).Value = CLng(a(i, j)). It depends whether you pass a Range to the function or assign the range to a variant first.