Declare leRange As String
and you'll get a String
that's empty. Your code has no bearing on the return type of Range.Value
, that's for Excel to decide.
The problem is that leRange
isn't just any other Variant/Empty
here: the range isn't spanning a single cell, so what the variant contains is actually a 2D array of variants, and that's how things work. You can't change the variant subtype of individual array elements you're getting from the host appliation's object model.
Variant/Empty
is not equivalent to an empty string: if a cell is effectively blank, then IsEmpty
returns true. If a cell contains/evaluates to an empty string, then IsEmpty
returns false.
Note that only a Variant
can hold an Error
value. If a cell evaluates to e.g. #REF!
, the variant subtype will be Variant/Error
, and IsError
will return true for it - trying to assign such a value to a String
will result in a type mismatch error.
Excel is giving you a variant array: your code needs to deal with a variant array. Empty
easily compares to ""
or vbNullString
(comparison evaluates to True) - there is no problem to solve, your worry about the variant subtype is misplaced, there's nothing to worry about.
Edit : The function, which takes those datas as argument, needs a variant of strings and i can't change it so i need to do the replacement.
I'm not sure what this means, but if it means you're passing the whole 2D Variant
array to a function that accepts a String()
array, then yes, you need to declare a new array and copy your variants into strings, otherwise you can expect a type mismatch - this is as inefficient as you would expect it to be given a few hundreds/thousands of cells, but if this is about the handful of cells involved in the OP, it shouldn't be too bad.