Finding last Cell and Copying down formula in multiple colums

argar418

New Member
Joined
Feb 10, 2013
Messages
3
Good morning,

I have the following code which works but only fills down one row and I want it to fill down to the last row but I cannot work it out.

Dim Col As Range
For Each Col In Range("L:Q").Columns
With Cells(Rows.Count, Col.Column).End(xlUp)
.Offset(1).Formula = .Formula
.Resize(2).FillDown
End With
Next

Can someone tell me how to get it to copy down to the last cell in all the columns.

Thanks for your help. Andrew

[TABLE="width: 1099"]
<tbody>[TR]
[TD]HKDDSHH[/TD]
[TD="align: right"]31-Jan-13[/TD]
[TD]HUS[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]-896.469[/TD]
[TD="align: right"]637.037[/TD]
[TD="align: right"]-636.555[/TD]
[TD="align: right"]-895.987[/TD]
[TD]January[/TD]
[TD]2013[/TD]
[TD]Comp[/TD]
[TD="align: right"]-112.059[/TD]
[TD]Thursday[/TD]
[TD]Midweek[/TD]
[/TR]
[TR]
[TD]HKDDSHH[/TD]
[TD="align: right"]31-Jan-13[/TD]
[TD]LBR[/TD]
[TD="align: right"]27[/TD]
[TD="align: right"]55[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"]3398.06[/TD]
[TD="align: right"]869.801[/TD]
[TD="align: right"]1137.463[/TD]
[TD="align: right"]5405.324[/TD]
[TD]January[/TD]
[TD]2013[/TD]
[TD]Transient[/TD]
[TD="align: right"]125.8541[/TD]
[TD]Thursday[/TD]
[TD]Midweek[/TD]
[/TR]
[TR]
[TD]HKDDSHH[/TD]
[TD="align: right"]31-Jan-13[/TD]
[TD]LCR[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]16[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]812.4588[/TD]
[TD="align: right"]403.5741[/TD]
[TD="align: right"]92.46083[/TD]
[TD="align: right"]1308.494[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]HKDDSHH[/TD]
[TD="align: right"]31-Jan-13[/TD]
[TD]LPP[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]HKDDSHH[/TD]
[TD="align: right"]31-Jan-13[/TD]
[TD]SOV[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]110.8105[/TD]
[TD="align: right"]116.1265[/TD]
[TD="align: right"]105.4556[/TD]
[TD="align: right"]332.3927[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]HKDDSHH[/TD]
[TD="align: right"]31-Jan-13[/TD]
[TD]Unknown[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody><colgroup><col><col><col span="15"></colgroup>[/TABLE]
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try on a copy of your data
Code:
Sub FillMe()
    Dim LstRw As Long
    LstRw = Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
    Range("L2:Q2").AutoFill Destination:=Range("L2:Q" & LstRw), Type:=xlFillDefault
End Sub

Edit: changed the ranges as I assume by the offset that you have headers
 
Last edited:
Upvote 0
Hey Mark,

Thanks for the answer, the issue is the sheet has 30000+ rows in it and will grow, so it errors out when filling from the toplines.

I have worked out if I amend the .Resize bracket to say 250 it works down 250 rows but the data is not standard so I need to resize with a variable rather than a defined number. I think, if that is possible.

Dim Col As Range
For Each Col In Range("L:Q").Columns
With Cells(Rows.Count, Col.Column).End(xlUp)
.Offset(1).Formula = .Formula
.Resize(250).FillDown
End With
Next
 
Upvote 0
Why would it error out at filling 30000+ rows? I just filled 200000 rows with formula and got no error.
 
Upvote 0
Hello Mark,

It was not working before as it showed an error but just tried again and it worked perfectly. Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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