VBA Code for fill down

James456

New Member
Joined
Jul 12, 2012
Messages
4
Hello,

I've tried finding an answer but have been unsuccessful so far - I need someone to spell this out for me I think!

In the Macro I'm trying to put together, I want to enter a formula into cell B2 (so far so good) and I want to copy the formula down as far as the last non-blank cell in column A.

So if I were simply in a spreadsheet, I would double click on the drag down square in the bottom right hand corner of the cell selected. That is all I'm trying to do - but within a macro.

Hope that's making some sense and fingers crossed somebody can help. Apologies if this has been answered before.

Cheers
James
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try like this

Code:
Sub test()
Dim LR As Long
LR = Range("A" & rows.Count).End(xlUp).Row
Range("B2").AutoFill Destination:=Range("B2:B" & LR)
End Sub
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Welcome to the board..

If you already have the formula that you put in B2, call it "Myformula"

Try
Rich (BB code):
Sub Test()
Dim lr As Long
lr = Cells(Rows.Count,"A").End(xlup).Row

'replace "MyFormula" with whatever formula you already have that works for B2
Range("B2:B" & lr).Formula = "MyFormula"
End sub

Hope that helps.
 

James456

New Member
Joined
Jul 12, 2012
Messages
4
Thank you guys, I tried both approaches and ran in to problems elsewhere in my code... Both I think the autofill part worked so thanks!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,119
Messages
5,599,821
Members
414,341
Latest member
Mohammedsobhey

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
Top