Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Relative VBA function

I've tried searching this forum, but can't find out how to do this.

I have a function that works correctly when the exact range is
specified. Now I want to copy my cell that uses this function to a big
table. How do I adjust the range call? Here is the code


Function myformula(a As Range, b As Range, c As Double,) As Variant

x = a.Columns.Count
y = b.Columns.Count

If x < y Then
myformula = "Error"
Exit Function
Else

For t = 1 To x
total = total + a.Cells(1, t) / (1 + b.Cells(1, t)) ^ (c + (t - 1))
Next t

myformula = total
End If

End Function


a() is Sheet2!A:b11:az11
b() is Sheet3!A:b11:az11
c=.25

Next data entry point is in row 22 (i.e. 11 rows down) but I want to
copy "myformula" entered in sheet1!a1 to sheet1!a2. When I do, the
referenced range a() changes to row 12 (as I would expect). Can I make
the "myformula" range a() drop 11 rows each time i copy it down without
actually copying it down 11 rows then moving the formula. I need to
repeat this formula 1000 by 20 times.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Relative VBA function

This isn't a problem with your macro, it's with how you use your
formula.

You should call your formula in a similar fashion to the following:

A1: = myformula(INDIRECT("Sheet2!AB" & ROW(A1)*11 & ":AZ" &
ROW(A1)*11), INDIRECT("Sheet3!AB" & ROW(A1)*11 & ":AZ" &
ROW(A1)*11),.25)

Note that you might have to make ROW(A1) in the above
(ROW(A1)-ROW($A$1)+1) if there is the risk of inserting rows... that
will make the formula more flexible. (Albeit somewhat larger) You can
also play with ADDRESS() to make it even more flexible.... but you
could end up with a messy looking formula. It all depends on how
robust you want to make it.

Scott

Brian wrote:
I've tried searching this forum, but can't find out how to do this.

I have a function that works correctly when the exact range is
specified. Now I want to copy my cell that uses this function to a big
table. How do I adjust the range call? Here is the code


Function myformula(a As Range, b As Range, c As Double,) As Variant
End Function


a() is Sheet2!A:b11:az11
b() is Sheet3!A:b11:az11
c=.25

Next data entry point is in row 22 (i.e. 11 rows down) but I want to
copy "myformula" entered in sheet1!a1 to sheet1!a2. When I do, the
referenced range a() changes to row 12 (as I would expect). Can I make
the "myformula" range a() drop 11 rows each time i copy it down without
actually copying it down 11 rows then moving the formula. I need to
repeat this formula 1000 by 20 times.

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Relative VBA function

What a bonehead I am! :-)

Thanks.

Brian

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Relative addressing with INDIRECT function john Excel Programming 7 June 8th 06 11:09 AM
Split function to get a relative path Jon[_21_] Excel Programming 1 April 2nd 06 11:56 PM
Get Relative Data from result of MIN function bigmacrox Excel Programming 0 January 4th 06 10:48 PM
HELP using simple TRIM function on relative columns Skip Albertson Excel Programming 2 December 27th 04 10:41 PM
Indirect function - relative reference Vladimir[_2_] Excel Programming 3 February 5th 04 09:05 PM


All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"