Hi
I'd like to use VBA to fill down a formula to a range of cells that will vary.
The formula will always be filled in column B, but the number of rows will vary, depending on how much data has been imported.
In the simple example below (where cell A1 has the title "Variables" and cells A2 to A5 have the values 1, 2, 3, and 4, respectively, I'd like to put in a formula in cell B2 that is then dragged down to all cells in column B, where there is a value in column A.
Does anyone know how to do this, please?
I've written the initial code (below) to put a formula into cell B2, but haven't dragged down to an unspecified number of cells before.
[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Variables[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[/TR]
</tbody>[/TABLE]
I'd like to use VBA to fill down a formula to a range of cells that will vary.
The formula will always be filled in column B, but the number of rows will vary, depending on how much data has been imported.
In the simple example below (where cell A1 has the title "Variables" and cells A2 to A5 have the values 1, 2, 3, and 4, respectively, I'd like to put in a formula in cell B2 that is then dragged down to all cells in column B, where there is a value in column A.
Does anyone know how to do this, please?
I've written the initial code (below) to put a formula into cell B2, but haven't dragged down to an unspecified number of cells before.
[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Variables[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub T1()
Range("b2").Select
ActiveCell.Formula = "=A2+A3"
End Sub