Fill down - dynamic range

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
644
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.

Variables
1
2
3
4

<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>


Code:
Sub T1()


Range("b2").Select
ActiveCell.Formula = "=A2+A3"
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Code:
    Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=A2+A3"
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top