View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default easy way to fill out a range with formulas?

Writing the first formula in the top cell of each column and then simply
dragging it down so that it autofills the range should increment the cell
references. Alternatively, particularly if range "names" is dynamic, you
could use a macro like this:

Sub x()
Dim c As Range

For Each c In Range("names")
c(1, 2).Formula = "=f(" & c.Address(False, False, xlA1) & ")"
c(1, 3).Formula = "=g(" & c.Address(False, False, xlA1) & ")"
Next
End Sub

Regards,
Greg


"dreamz" wrote:


hi,

i have a spreadsheet that is set up like a matrix, names on the left,
different metrics along the top.

example:

Code:
--------------------
f and g are different functions with the name as argument (e.g., a lookup function)

name metric1 metric2
aaa f(aaa) g(aaa)
bbb f(bbb) g(bbb)
ccc f(ccc) g(ccc)
ddd f(ddd) g(ddd)
--------------------


now, i have the name column set up as a named range. i can write
something like:


Code:
--------------------
Range("name").Offset(0, 1).Value = "=f(a1)"
--------------------

in other words, explicitly write the function into the cell relative to
the named range, but this is inefficient when i have 60 or so columns to
fill out. is there an easy way to do this? i'm trying to avoid
copy/paste because it's slow.

i cannot keep the formulas in there because there are hundreds of lines
per sheet, and it needs to be clean (i.e. exactly as long as the named
range) for the task at hand.

thanks.


--
dreamz
------------------------------------------------------------------------
dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
View this thread: http://www.excelforum.com/showthread...hreadid=533040