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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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
 
Upvote 0
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.
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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