Fill formula down using macro

C

Charles

hi, using VBA I would like to fill a formula down to end of my data rather
than to a fixed cell as the size of my data is different each time I run my
macro.
 
M

Mike

Const formulaStartingCell As String = "C2"
Dim lastrow As Long
'replace A to the column that will always be the last row
lastrow = Range("A" & Rows.Count).End(xlUp).Row

Range(formulaStartingCell).Activate
Selection.AutoFill Destination:=Range(formulaStartingCell & ":C" &
lastrow), Type:=xlFillDefault
 
S

Shane Devenshire

Hi,

Here is one example which puts the formula in all the cells

LastCell = [A1].End(xlDown).Row
Range([B1], "B" & LastCell) = "=COUNTIF(INDIRECT(R1C&""!A1:D10""),RC1)"

Note this is not a fill down command it puts the formula of interest in all
the cells indicated.

Cheers,
Shane Devenshire
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top