Fill formula to last row

eolivier

New Member
Joined
Nov 25, 2015
Messages
23
Hello,

I do not know how to write code, but only how to record macros. I have 3 adjacent cells with vlookup formulas (E2, F2, and G2), and i want the formula to fill to last row with data. Each time the macro is ran, it will start in the same spot (E2:G2), but will have a different end point depending on how many rows of data are being added.

Here is the code that was recorded:

Range("E2:G2").Select
Selection.AutoFill Destination:=Range("E2:G2519")

How can i change the destination range to go to the last row, and not a specific range?

Thanks,

Erik
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
you don't need to select the range with the formulas:
Code:
Dim lR As Long
lR = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
Range("E2:G" & lR).FillDown
 
Upvote 0
Assuming the values in Range("E2:G2") is text then use this script:
Code:
Sub Fill_Down()
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "G").End(xlUp).Row - 2
Range("E2:G2").Resize(Lastrow).Value = Range("E2:G2").Value
End Sub
 
Upvote 0
Thank you. After doing more research, this is the solution I came up with...

Dim lastrow As Long
lastrow = Range("D" & Rows.Count).End(xlUp).Row
...
Range("E2:G2").Select
Selection.AutoFill Destination:=Range("E2:G" & lastrow)
 
Upvote 0
Glad to see you figured that out on your own.
I was in the process of sending you an answer in case the values were formulas but a phone call interrupted me and then I saw you came up with a solution. I think using places like Mr. Excel are excellent for learning I just hope people do not just look for scripts to copy and not attempt to learn scripting. Sort of like the old adage. Teach a man to fish and I think you know the rest.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,238
Members
448,555
Latest member
RobertJones1986

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