Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill formula down till last row in column

Tags:

excel

vba

formula

I'm trying to draw down the formula that's in cell M3 to the end of the data set.

I'm using column L as my base to determine the last cell with data. My formula is a concatenation of two cells with a text comma in-between them.

My formula is =G3&","&L3

I want Excel to draw down this formula so

Cell M4 would be =G4&","&L4
Cell M5 would be =G5&","&L5 and so on.

My code:

Range("$M$3").Formula = Range("G3") & (",") & Range("L3")

Dim Lastrow As Long

Application.ScreenUpdating = False

Lastrow = Range("L" & Rows.Count).End(xlUp).Row
Range("M4").FormulaR1C1 = Range("G4") & (",") & Range("L4")
Range("M4").AutoFill Destination:=Range("M4:M" & Lastrow)
ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True

My output is pulling down the text values from cell M3 all the way down to the end of the data set. I've searched around for several hours trying to look for a fix, but can't find one that is trying to accomplish what I'm going for.

like image 619
MatTtT Avatar asked Sep 11 '14 13:09

MatTtT


People also ask

How do I extend a formula to an entire column?

Just select the cell F2, place the cursor on the bottom right corner, hold and drag the Fill handle to apply the formula to the entire column in all adjacent cells.

How do I autofill the rest of a column?

Method #1: Ctrl + D Click in the cell with the data and, keeping the left mouse button pressed, drag to select the rest of the cells in the row or column that you would like autofilled. Release the mouse button. Press Ctrl + D (the Ctrl key is held while the D key is pressed) and the cells are filled.


1 Answers

It's a one liner actually. No need to use .Autofill

Range("M3:M" & LastRow).Formula = "=G3&"",""&L3"
like image 179
Siddharth Rout Avatar answered Oct 20 '22 18:10

Siddharth Rout