How to paste formulas down to the end of a range using VBA

Mr2017

Active Member
Joined
Nov 28, 2016
Messages
458
Hi Guys!

I'll provide a simple example of what I'd like to do:

I have some formulae in cells E1 and F1 and I'd like to copy and paste them to cell E2 to F2 AFTER data has been pasted in the preceding columns (A:D) until the end of the range of the data in columns A to D.

The data in columns A to D could go from row 2 to row 100, or from row 2 to row 1000.

Does anyone know how to do this, please?

I've pasted very simple formulae below, to save you time:

This formula should go in cell E1: =A1+B1

This formula should go in cell F1: ==C1+D1

Thanks in advance!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
Try
Code:
Sub Mr2017()
   Range("E2", Range("A" & Rows.Count).End(xlUp).Offset(, 5)).Filldown
End Sub
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,900
Office Version
2007
Platform
Windows
Try this

Code:
Sub fill()
    Range("E1:F1").AutoFill Destination:=Range("E1:F" & Range("A" & Rows.Count).End(xlUp).Row)
End Sub
 

Mr2017

Active Member
Joined
Nov 28, 2016
Messages
458
Hi Fluff

Thanks for the prompt response.

I tried that code, but nothing happened with my sheet?

I used the data below (which you can copy and paste into cell A1 - it then populates data from cell A1:D5). And I kept the formulae the same in cells E1 and F1 ie =A1+B1 in cell E1 and =C1+D1 in cell F1. However, the code in the post subsequently below, worked - so I've used that, in the meantime.

4632105
1122
1122
1122
1122

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

Mr2017

Active Member
Joined
Nov 28, 2016
Messages
458
Thanks Dante.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
Try changing the E2 in my code to E1
 

Mr2017

Active Member
Joined
Nov 28, 2016
Messages
458
Ok, yes, it works as intended, now, Fluff.

Thanks for clarifying that.
 
Last edited:

Forum statistics

Threads
1,082,369
Messages
5,365,049
Members
400,819
Latest member
Gossow

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top