View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Anthony[_14_] Anthony[_14_] is offline
external usenet poster
 
Posts: 2
Default Using Relative Reference Function to apply to Range

All,

I've written a function that looks at a range of cells and adds them up
based on the Offset function. The range of cells will change based on
another defined range's contents.

What I want to be able to do is copy the function down several rows and
have that same range added via a relative reference however with the
code attached, all the cells that have the formula get updated to the
last cell that where the function was applied. I understand why my
logic isn't right but does anyone have an idea how to make this work?

Thanks for the input.

--------------

Function YTDMonths()

Dim intMonthCount As Integer, b As Integer, c As String
Dim TempSum As Double
Dim aRange

ActiveCell.Select

'Determines how far into the range to add (based on month in another
defined range)

Select Case Range("CurrentMonth")
Case Is = 38718: intMonthCount = 11
Case Is = 38749: intMonthCount = 12
Case Is = 38777: intMonthCount = 13
Case Is = 38808: intMonthCount = 14
Case Is = 38838: intMonthCount = 15
Case Is = 38869: intMonthCount = 16
Case Is = 38899: intMonthCount = 17
Case Is = 38930: intMonthCount = 18
Case Is = 38961: intMonthCount = 19
Case Is = 38991: intMonthCount = 20
Case Is = 39022: intMonthCount = 21
Case Is = 39052: intMonthCount = 22
End Select

TempSum = 0

'c = ActiveCell.Address
'Debug.Print c

For b = 11 To intMonthCount
TempSum = TempSum + ActiveCell.Offset(0, b).Value
Next

YTDMonths = TempSum
Calculate
End Function