Keeping empty values empty (not zero)

V

vsoler

I'm working with an array (copied from a range) that contains some
null, empty or "" values (I do not know how to call them). When I copy
the array back to the range these empty values are converted into
zeroes, which is an undesired result for me. I would like them to stay
as empty.

How can I do it? (I think reading the code through is not necessary)
Any help is appreciated
********************************************************************************

Function Igual2(Rng As Range) As Variant
Dim Vector() As Variant
Dim i As Integer, j As Integer
Vector = Rng.Value
i = UBound(Vector, 1)
ReDim Preserve Vector(1 To i, 1 To 2)
For j = 1 To i
Vector(j, 2) = j
Next j
Vector = BubbleSort(Vector)
Igual2 = Vector
End Function

Function BubbleSort(List())
Dim First As Integer, Last As Integer
Dim i As Integer, j As Integer
Dim Temp
First = LBound(List)
Last = UBound(List)
For i = 1 To Last - 1
For j = i + 1 To Last
If List(i, 1) > List(j, 1) Then
Temp = List(j, 1)
List(j, 1) = List(i, 1)
List(i, 1) = Temp
End If
Next j
Next i
BubbleSort = List
End Function
 
D

Dave Peterson

Convert them to "" when you pick them up--or before you put them back:

Function Igual2(Rng As Range) As Variant
Dim Vector() As Variant
Dim i As Integer, j As Integer
Vector = Rng.Value
i = UBound(Vector, 1)
ReDim Preserve Vector(1 To i, 1 To 2)
For j = 1 To i
Vector(j, 2) = j
Next j
Vector = BubbleSort(Vector)
For j = 1 To UBound(Vector, 1)
If Vector(j, 1) = "" Then
Vector(j, 1) = ""
End If
Next j
Igual2 = Vector
End Function

(I did it before I put them back.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top