macros program

S

Steph

I am trying to write a macros program.

How can I get excel to subtract the last numer in a column from the first
number in the same column?

The range is always different
 
G

Gary''s Student

Try this UDF:


Function top2bottom(i As Integer) As Double
Dim top As Double
Dim bot As Double
Dim j As Long
top = 0
bot = 0
top2bottom = 0

If i > 255 Then
Exit Function
End If

For j = 1 To 65536
If Application.IsNumber(Cells(j, i)) Then
top = Cells(j, i).Value
Exit For
End If
Next

For j = 65536 To 1 Step -1
If Application.IsNumber(Cells(j, i)) Then
bot = Cells(j, i).Value
Exit For
End If
Next

top2bottom = top - bot

End Function


For column A use =top2bottom(1)
 
Top