ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Fill formula down using macro (https://www.excelbanter.com/excel-discussion-misc-queries/210101-fill-formula-down-using-macro.html)

charles

Fill formula down using macro
 
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.

Mike

Fill formula down using macro
 
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

"Charles" wrote:

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.


Shane Devenshire[_2_]

Fill formula down using macro
 
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


"Charles" wrote:

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.



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com