Autofill from Last Row

Ryan Hoofe

New Member
Joined
Jul 25, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Morning All,

Im looking to autofill a column from the last used row, this will vary day by day so im struggling with what the range should be as this will be variable each time? Sorry if this is a silly question I'm very new to VBA!

This is the code i have currently

Rich (BB code):
    Range("K1").Select
    Range("K" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-1]C[-2],'YTD EE'!C[-10]:C[-9],2,0)"
    Range("L1").Select
    Range("L" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(R[-1]C[-2],'YTD Supplier'!C[-11]:C[-10],2,0)"
    Range("L305632").Select
    Range("K1").Select
    Selection.End(xlDown).Select
    Selection.AutoFill Destination:=Range("K305631:K307455")
    Range("K305631:K307455").Select
    Range("L1").Select
    Selection.End(xlDown).Select
    Selection.AutoFill Destination:=Range("L305631:L307455")
   Range("L305631:L307455").Select

Thanks
 
Last edited by a moderator:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to the forum. :)

Which column should the code use to determine the last row to fill to? Given that your formulas refer to the row above, should the formulas extend one row past the data in column I for example?
 
Upvote 0
Yes correct Column I can be the identifier for what row it should autofill down to. The formula should autofill to the last row that column I has data in.

The reason for going 1 row below when entering the formula is because sometimes the formula gets overwritten at a future step so i cant just do range K2:K30000 (wouldve been much easier if i could! :biggrin:)
 
Upvote 0
I don't follow your last comment? I was referring to the fact that your formula is looking up a value from the row above the row with the formula.

Anyway, you could use something like:

VBA Code:
   Dim fillToRow As Long
   fillToRow = Cells(Rows.Count, "I").End(xlUp).Row
   Dim fillFromRow As Long
   fillFromRow = Cells(Rows.Count, "K").End(xlUp).Row
   
    With Range("K" & fillFromRow & ":K" & fillToRow)
      .FormulaR1C1 = "=VLOOKUP(R[-1]C[-2],'YTD EE'!C1:C2,2,0)"
      .Offset(, 1).FormulaR1C1 = "=VLOOKUP(R[-1]C[-2],'YTD Supplier'!C1:C2,2,0)"
   End With
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

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