Copy a formula down in a macro

S

Sal

I have information in column A and I wish to write a macro that:

1. Populates cell B2 with a VLOOKUP formula
2. The macro is then to copy the above formula down to the last active cell
in column A

I have tried so many things that I am in a bid of a muddle. Any suggestions
will be very welcome.

Thanks
 
M

mudraker

Just modify the formula to equal your lookup formula

Sub Macro1()

Dim LastRow As Long
LastRow = Cells(Rows.Count, "a").End(xlUp).Row
Range("a1").Value = "=b1+1"
Range("a1:a1").AutoFill _
Destination:=Range("A1:A" & LastRow), Type:=xlFillDefault
End Sub
 
S

Sal

Thank you so much - I just changed the cell references around a wee bit and
it works perfectly.

Your help is much appreciated!!
 
D

Dave Peterson

dim LastRow as long
with worksheets("sheet9999")
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("B2:b" & lastrow).formula _
= "=vlookup(a2,'sheet 333'!a:e,5,false)"
end with

will fill that range with a vlookup formula.
 
Top