Hi all,
My boss encountered a weird problem today but I am unable to post snippets of the code as it is part of a corporate .xlam library.
Basically, a function was written to take in a range using a variant parameter. Range that was passed in was an entire column, meaning 1048576 rows.
Each cell contains doubles but some are whole numbers (essentially longs).
Basically, the function loops through the cells in vba and pass the non-empty cells into another array.
The weird part:
- when assigning the range to a variant array, cells with decimals are empty (Dim vTemp as variant: vTemp = Range("A:A") - for example)
- this prompted investigation by breaking at that line of code
- accessing the range object direction via rng.Cells(i,j) returns the value with decimals
- further running of the code reveals that the function is called twice (or multiple times) and on the second pass, the decimal values appear in the variant array
Can anyone think of any potential cause for this phenomenon?
Is it documented anywhere that, due to the sheer size of the range object, the longs are loaded first, followed by the doubles?
Thanks in advance for your help!
My boss encountered a weird problem today but I am unable to post snippets of the code as it is part of a corporate .xlam library.
Basically, a function was written to take in a range using a variant parameter. Range that was passed in was an entire column, meaning 1048576 rows.
Each cell contains doubles but some are whole numbers (essentially longs).
Basically, the function loops through the cells in vba and pass the non-empty cells into another array.
The weird part:
- when assigning the range to a variant array, cells with decimals are empty (Dim vTemp as variant: vTemp = Range("A:A") - for example)
- this prompted investigation by breaking at that line of code
- accessing the range object direction via rng.Cells(i,j) returns the value with decimals
- further running of the code reveals that the function is called twice (or multiple times) and on the second pass, the decimal values appear in the variant array
Can anyone think of any potential cause for this phenomenon?
Is it documented anywhere that, due to the sheer size of the range object, the longs are loaded first, followed by the doubles?
Thanks in advance for your help!