Unwanted conversion from Null to Zero

V

vsoler

I am missing something...

A zero value eventually shows in the spreadsheet as zero.

Let me explain: my Function has a Range (a vertical vector) as a
parameter. The range may contain empty cells. The range is then
converted to a Variant that contains an array. The function puts all
the Null (empty) values at the bottom of the array. Till here
everything is fine.

But in the spreadsheet, instead of empty cells I see zeroes, which is
wrong. What am I missing?

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 = NullsAtTheBottom(Vector)
....
Igual2 = Vector
End Function
 
J

JLGWhiz

You can go to Tools>Options>View and uncheck "zero values". Excel otherwise
will convert null to zero.
 
V

vsoler

You need to post the code of NullsAtTheBottom.

RBS

Here is the code for NullsAtTheBottom: what's wrong with it?

Function NullsAtTheBottom(List()) As Variant
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
If List(i, 1) = "" Then
For j = i + 1 To Last
If List(j, 1) <> "" Then
Temp = List(j, 1)
List(j, 1) = List(i, 1)
List(i, 1) = Temp
End If
Next j
End If
Next i
NullsAtTheBottom = List
End Function
 

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