View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default copy down with variable number of rows

Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
.Range("a1:c1").AutoFill _
Destination:=.Range("A1:C" & LastRow), Type:=xlFillDefault
End With


But you may find that you can just populate the formulas in each column:

Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
.Range("a1:A" & lastrow).formula = "=formulaforA1Here"
.Range("b1:b" & lastrow).formula = "=formulaforb1Here"
.Range("c1:c" & lastrow).formula = "=formulaforc1Here"
End With




mohavv wrote:

Hi,

I would like to add a copy down function into a macro but the number
of rows varies.

I insert 3 columns A to C and add formulas in the first 3 cells
(A1:C1). These formulas need to be copied down as long as there are
values in colums D (= to the first blank cell in D). Like the auto
fill function.

How can I do this?

With the macro recorder using the autofill it gives me a fixed range.

Cheers,

Harold


--

Dave Peterson