Copying down a formula in a variable length range?

parodytx

New Member
Joined
Feb 17, 2008
Messages
23
I have a spreadsheet that builds from existing data. The number of rows may vary depending on the data required, but all rows are filled and consecutive.

I need to copy down a formula in a column from the top cell, but I can't get the logic to work in getting the Range().Select or ActiveCell.Offset() to work.

So, for clarity, I have columns A & B that have data say from cells A1:B20, and I need to copy the Formula +A1 + B1 to Cell C1, then copy it down for as long as there are rows with data in columns A & B, without overtly looping to a fixed count of 20.

All help is much appreciated.

Excel 2010 Windows 7 32 Bit
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Like this you mean?
Code:
Sub Maybe()
    Dim lr As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    With Range("A1:A" & lr).Offset(, 2)
        .Formula = "=RC[-2]+RC[-1]"
    End With
End Sub
 
Upvote 0
or another method

Sub plus()
Dim a, b As Variant
Do
a = a + 1
b = Range("a" & Rows.Count).End(xlUp).Row
Range("c" & a) = Application.WorksheetFunction.Sum(Range("a" & a) + Range("b" & a))
If a = b Then Exit Sub
Loop
End Sub
 
Upvote 0
or another method

Sub plus()
Dim a, b As Variant
Do
a = a + 1
b = Range("a" & Rows.Count).End(xlUp).Row
Range("c" & a) = Application.WorksheetFunction.Sum(Range("a" & a) + Range("b" & a))
If a = b Then Exit Sub
Loop
End Sub


Thanks so much - this did not work exactly for me (My formula example was too simplistic - my fault) but it got me to see the place I needed to be in my logic. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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