views:

167

answers:

1

Consider the following data on excel(which you have to create in excel): Numbers

0.2
0.2
3.4

1.5
1.8

4.2

Write a VBA function that scans through the selection, finds the empty spots and then t fills them with a numerical value which is passed through the signature of the function. Output: Numbers

0.2
0.2
3.4
0
1.5
1.8
0.0
4.2

Hi everyone, i have a question above.

I was wondering if anyone can look at my code and tell me whats wrong with my code.

Public Function MyFill(thisRange As Range)
Dim x As Range
Set x = thisRange
ReDim Y(x.Length)
Dim i As Integer
For Each x In thisRange
    If (x.Value = Empty) Then
        Y(i) = 0
        i = i + 1
    End If
    Y(i) = x.Value
Next x
MyFill = Y
End Function
A: 
Public Function MyFill(thisRange As Range)
Dim X As Range
Set X = thisRange
MyFill = X
End Function

Apparently the answer i was looking for is much simpler than I thought.

That doesn't change the range in any way. In fact this function does nothing at all
barrowc