ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macros program (https://www.excelbanter.com/excel-discussion-misc-queries/70662-macros-program.html)

Steph

macros program
 
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

Gary''s Student

macros program
 
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)
--
Gary''s Student


"Steph" wrote:

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



All times are GMT +1. The time now is 04:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com